Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 51 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import dotenv from "dotenv"; |
||
2 | import express from "express"; |
||
3 | import cors from "cors"; |
||
4 | import morgan from "morgan"; |
||
5 | |||
6 | |||
7 | |||
8 | |||
9 | dotenv.config(); |
||
10 | // dotenv.config({ path: '.env' }); |
||
11 | |||
12 | import apiRouter from "./routes/v1/index.js"; |
||
13 | import errorHandler from "./src/middleware/error-handler.js"; |
||
14 | // import apiKeyHandler from "./src/middleware/apiKey-handler.js"; |
||
15 | |||
16 | const app = express(); |
||
17 | const port = 1337; |
||
18 | |||
19 | app.use(morgan("dev")); |
||
20 | |||
21 | app.use(cors()); |
||
22 | app.use(express.json()); |
||
23 | |||
24 | app.use(express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded |
||
25 | |||
26 | // TODO: Här kan vi lägga in en middleware för att kolla API-nyckel? |
||
27 | // app.use(apiKeyHandler); |
||
28 | |||
29 | app.use("/v1", apiRouter); |
||
30 | |||
31 | app.use(errorHandler); |
||
32 | |||
33 | // just for testing via browser |
||
34 | // import userModel from "./src/models/user.js"; |
||
35 | |||
36 | |||
37 | |||
38 | // /** |
||
39 | // * Just to check that database connection |
||
40 | // * is working.. will remove later |
||
41 | // */ |
||
42 | // app.get("/", async (req, res) => { |
||
43 | // const result = await userModel.allPag(10, 3); |
||
44 | // res.json(result); |
||
45 | // }); |
||
46 | |||
47 | app.listen(port, () => { |
||
48 | console.log(`Server running on port ${port}`); |
||
|
|||
49 | }); |
||
50 | |||
51 | export default app; |
||
52 |