-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
46 lines (36 loc) · 1.19 KB
/
app.ts
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
import express, { Request, Response } from "express";
import login from "./src/routes/login.routes";
import cursos from "./src/routes/cursos.routes";
import bodyParser from "body-parser";
import path from "path";
import cors from "cors";
require("dotenv").config();
//Inicia Server
const app = express();
const port = process.env.PORT;
// Servir arquivos estáticos da pasta 'dist'
app.use("/dist",express.static(path.join(__dirname, "dist")));
// Servir arquivos estáticos da pasta 'dist/user'
app.use("/user", express.static(path.join(__dirname, "dist", "user")));
// Configuração do CORS
const corsOptions = {
origin: ["https://cursos.bytebushido.tech", "http://whalter.serveirc.com:3000"] ,
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true,
optionsSuccessStatus: 200,
};
app.use(cors(corsOptions));
//Body Parser
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//Rotas
//Home
app.use("/", login);
app.use("/cursos", cursos);
//Para rotas não encotradas
app.use((req: Request, res: Response) => {
res.status(404).json({ Server: "Pagina não encontrada" });
});
app.listen(port, () => {
console.log(`Servidor rodando em ${process.env.BASE}`);
});