aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRitesh Ghosh <[email protected]>2023-11-29 19:32:09 +0530
committerGitHub <[email protected]>2023-11-29 19:32:09 +0530
commitc15c194031ca5053d2cd143336544271b176ad93 (patch)
treed6bb7d52c128eda8f124d6c5a70aa9ecb93b5e8c
parentb9cf76d9aeb70e2dc1e5f2c31ec580f018a96812 (diff)
parentc079bf808ab2e6ec7fa58832f842b05e6212111a (diff)
downloadaniwatch-api-c15c194031ca5053d2cd143336544271b176ad93.tar.xz
aniwatch-api-c15c194031ca5053d2cd143336544271b176ad93.zip
Merge pull request #9 from ghoshRitesh12/vercel
Add Vercel deployment support
-rw-r--r--Dockerfile5
-rw-r--r--api/index.ts3
-rw-r--r--package.json3
-rw-r--r--src/server.ts23
-rw-r--r--vercel.json8
5 files changed, 30 insertions, 12 deletions
diff --git a/Dockerfile b/Dockerfile
index e57ab2a..755ab99 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -17,7 +17,8 @@ RUN npm run build
FROM node:20-alpine as prod
LABEL org.opencontainers.image.source=https://github.com/ghoshRitesh12/aniwatch-api
-LABEL org.opencontainers.image.description="Aniwatch API docker image"
+LABEL org.opencontainers.image.description="Node.js API for obtaining anime information from aniwatch.to (formerly zoro.to) written in TypeScript, made with Cheerio & Axios"
+LABEL org.opencontainers.image.description "Node.js API for obtaining anime information from aniwatch.to (formerly zoro.to) written in TypeScript, made with Cheerio & Axios"
LABEL org.opencontainers.image.licenses=MIT
# create a non-privileged user
@@ -52,6 +53,6 @@ ENV PORT=4000
# exposed port
EXPOSE 4000
-CMD [ "node", "dist/server.js" ]
+CMD [ "node", "dist/src/server.js" ]
# exit \ No newline at end of file
diff --git a/api/index.ts b/api/index.ts
new file mode 100644
index 0000000..be3392b
--- /dev/null
+++ b/api/index.ts
@@ -0,0 +1,3 @@
+import app from "../src/server.js";
+
+export default app;
diff --git a/package.json b/package.json
index 422a1c4..0753fbf 100644
--- a/package.json
+++ b/package.json
@@ -8,6 +8,7 @@
"start": "tsx src/server.ts",
"dev": "tsx watch src/server.ts",
"build": "tsc -p tsconfig.json",
+ "vercel-build": "echo \"Hello\"",
"prepare": "husky install",
"test": "jest",
"healthcheck": "curl -f http://localhost:4000/health"
@@ -49,6 +50,6 @@
"jest": "^29.6.2",
"ts-jest": "^29.1.1",
"tsx": "^4.2.0",
- "typescript": "^5.1.6"
+ "typescript": "^5.3.2"
}
} \ No newline at end of file
diff --git a/src/server.ts b/src/server.ts
index c10b91f..31f53ab 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -26,12 +26,17 @@ app.use("/anime", animeRouter);
app.use(notFoundHandler);
app.use(errorHandler);
-app.listen(PORT, () => {
- console.log(`⚔️ api @ http://localhost:${PORT}`);
-});
-
-// don't sleep
-setInterval(() => {
- console.log("HEALTHCHECK ;)", new Date().toLocaleString());
- https.get("https://api-aniwatch.onrender.com/health");
-}, 540000);
+if (!Boolean(process?.env?.IS_VERCEL_DEPLOYMENT)) {
+ app.listen(PORT, () => {
+ console.log(`⚔️ api @ http://localhost:${PORT}`);
+ });
+
+ // don't sleep
+ // remove the setInterval below for personal deployments
+ setInterval(() => {
+ console.log("HEALTHCHECK ;)", new Date().toLocaleString());
+ https.get("https://api-aniwatch.onrender.com/health");
+ }, 540000);
+}
+
+export default app;
diff --git a/vercel.json b/vercel.json
new file mode 100644
index 0000000..2bc8c24
--- /dev/null
+++ b/vercel.json
@@ -0,0 +1,8 @@
+{
+ "rewrites": [
+ {
+ "source": "(.*)",
+ "destination": "/api"
+ }
+ ]
+} \ No newline at end of file