feat: disabled ratelimit & dont_sleep for personal deployments
This commit is contained in:
+25
-8
@@ -17,7 +17,14 @@ const PORT: number = Number(process.env.PORT) || 4000;
|
|||||||
|
|
||||||
app.use(morgan("dev"));
|
app.use(morgan("dev"));
|
||||||
app.use(corsConfig);
|
app.use(corsConfig);
|
||||||
app.use(ratelimit);
|
|
||||||
|
// CAUTION: For personal deployments, "refrain" from having an env
|
||||||
|
// named "ANIWATCH_API_HOSTNAME". You may face rate limitting
|
||||||
|
// and other issues if you do.
|
||||||
|
const ISNT_PERSONAL_DEPLOYMENT = Boolean(process?.env?.ANIWATCH_API_HOSTNAME);
|
||||||
|
if (ISNT_PERSONAL_DEPLOYMENT) {
|
||||||
|
app.use(ratelimit);
|
||||||
|
}
|
||||||
|
|
||||||
app.use(express.static(resolve("public")));
|
app.use(express.static(resolve("public")));
|
||||||
app.get("/health", (_, res) => res.sendStatus(200));
|
app.get("/health", (_, res) => res.sendStatus(200));
|
||||||
@@ -26,18 +33,28 @@ app.use("/anime", animeRouter);
|
|||||||
app.use(notFoundHandler);
|
app.use(notFoundHandler);
|
||||||
app.use(errorHandler);
|
app.use(errorHandler);
|
||||||
|
|
||||||
|
// NOTE: this env is "required" for vercel deployments
|
||||||
if (!Boolean(process?.env?.IS_VERCEL_DEPLOYMENT)) {
|
if (!Boolean(process?.env?.IS_VERCEL_DEPLOYMENT)) {
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`⚔️ api @ http://localhost:${PORT}`);
|
console.log(`⚔️ api @ http://localhost:${PORT}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// don't sleep
|
// NOTE: remove the `if` block below for personal deployments
|
||||||
// remove the setInterval below for personal deployments
|
if (ISNT_PERSONAL_DEPLOYMENT) {
|
||||||
const intervalTime = 9 * 60 * 1000; // 9mins
|
// don't sleep
|
||||||
setInterval(() => {
|
const intervalTime = 9 * 60 * 1000; // 9mins
|
||||||
console.log("HEALTHCHECK ;)", new Date().toLocaleString());
|
setInterval(() => {
|
||||||
https.get("https://api-aniwatch.onrender.com/health");
|
console.log("HEALTHCHECK ;)", new Date().toLocaleString());
|
||||||
}, intervalTime);
|
https
|
||||||
|
.get(
|
||||||
|
new URL("/health", `https://${process.env.ANIWATCH_API_HOSTNAME}`)
|
||||||
|
.href
|
||||||
|
)
|
||||||
|
.on("error", (err) => {
|
||||||
|
console.error(err.message);
|
||||||
|
});
|
||||||
|
}, intervalTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
Reference in New Issue
Block a user