aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRitesh Ghosh <[email protected]>2023-08-07 14:42:22 +0530
committerRitesh Ghosh <[email protected]>2023-08-07 14:42:22 +0530
commitf5a774ce494441b7ed06851c55c22eba9fd330fd (patch)
tree26580c4ca7d7f4d2c66f8702dafc7345278811bd /src
parent552b787a63e89026391aac368dc37a8837bf446e (diff)
downloadaniwatch-api-f5a774ce494441b7ed06851c55c22eba9fd330fd.tar.xz
aniwatch-api-f5a774ce494441b7ed06851c55c22eba9fd330fd.zip
chore(cleanup): cleaned up server.ts
Diffstat (limited to 'src')
-rw-r--r--src/server.ts45
1 files changed, 8 insertions, 37 deletions
diff --git a/src/server.ts b/src/server.ts
index 1b7e8e8..d74635a 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -1,50 +1,21 @@
-import express, {
- Request,
- Response,
- NextFunction,
- ErrorRequestHandler,
- Application,
-} from "express";
-
-import { config } from "dotenv";
import morgan from "morgan";
-import createHttpError from "http-errors";
+import env from "./config/env";
+import express, { Application } from "express";
import animeRouter from "./routes";
+import { homePage } from "./controllers";
+import errorHandler from "./config/errorHandler";
+import notFoundHandler from "./config/notFoundHandler";
-config();
const app: Application = express();
-const PORT: number = Number(process.env.PORT) || 4000;
+const PORT: number = env.PORT || 4000;
app.use(morgan("dev"));
-app.get("/", (req: Request, res: Response) => {
- res.send(`
- <body style="font-family: sans-serif; background: #000; color: #FFF;">
- <h3>Welcome to Zoro.to api ⚔️</h3>
- <a
- style="color: #00AEDD;"
- href="https://github.com/ghoshRitesh12/zoro.to-api#readme"
- rel="noopener noreferer"
- >
- Visit docs for more into
- </a>
- </body>
- `);
-});
+app.get("/", homePage);
app.use("/anime", animeRouter);
-app.use((req: Request, res: Response, next: NextFunction) =>
- next(createHttpError.NotFound())
-);
-
-const errorHandler: ErrorRequestHandler = (error, req, res, next) => {
- const status = error?.status || 500;
- res.status(status).json({
- status,
- message: error?.message || "Something Went Wrong",
- });
-};
+app.use(notFoundHandler);
app.use(errorHandler);
app.listen(PORT, () => {