-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·53 lines (48 loc) · 1.32 KB
/
Copy pathserver.js
File metadata and controls
executable file
·53 lines (48 loc) · 1.32 KB
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
53
import express from "express";
import http from "http";
import cors from "cors";
import morgan from "morgan";
import routerApi from "./routes/index.js";
import bodyParser from "body-parser";
import {
logErrors,
boomErrorHandler,
errorHandler,
} from "./middlewares/error.handler.js";
import { authenticateJWT } from "./middlewares/auth.handler.js";
import { connectDB } from "./libs/db.js";
const server = express();
const app = http.createServer(server);
server.use(bodyParser.json({ limit: "5mb" }));
server.use(express.json());
server.use(express.urlencoded({ extended: true }));
const whitelist = [
"http://localhost:8000",
"http://localhost:3000",
"http://localhost:3001",
"http://localhost:3002",
"http://localhost:5000",
"https://storage.googleapis.com",
"https://accounts.google.com",
];
const options = {
origin: (origin, callback) => {
if (whitelist.includes(origin) || !origin) {
callback(null, true);
} else {
callback(new Error("no permitido"));
}
},
};
server.use(cors(options));
// connectDB(); // Conexión a MongoDB
server.get("/", (req, res) => {
res.send("Hola mundo");
});
// server.use(authenticateJWT);
routerApi(server);
server.use(morgan("combined")); //dev, tiny, common
server.use(logErrors);
server.use(boomErrorHandler);
server.use(errorHandler);
export { app };