aboutsummaryrefslogtreecommitdiff
path: root/src/server.ts
blob: 1b7e8e81d914abf2d62cc9f0e358bc6ccb10ddf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import express, {
  Request,
  Response,
  NextFunction,
  ErrorRequestHandler,
  Application,
} from "express";

import { config } from "dotenv";
import morgan from "morgan";
import createHttpError from "http-errors";

import animeRouter from "./routes";

config();
const app: Application = express();
const PORT: number = Number(process.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.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(errorHandler);

app.listen(PORT, () => {
  console.log(`⚔️  api @ http://localhost:${PORT}`);
});