-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (34 loc) · 1.42 KB
/
index.js
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
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
//const helmet = require('helmet');
const apiRouter = require('./routers/api.js');
const loginRouter = require('./routers/login.js');
const registrarRouter = require('./routers/registrar.js');
var cors = require('cors')
const app = express();
app.use(cors())
app.use(function(req, res, next) {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS');
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
next();
});
const PORT = process.env.PORT || 5000;
const connString = process.argv[2];
//app.use(helmet());
app.use(express.static('dist'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
//ESTE TRECHO AUTORIZA REQUISICOES DE DIFERENTES END-POINTS (CROSS ORIGN REQUEST), DESTA FORMA CONSIGO CONSUMIR
//A API NO MEU AMBIENTE DE DESENVOLVIMENTO, AO COLOCAR O APP EM PRODUÇÃO NUMA VERSÃO ESTÁVEL REMOVER TRECHO ABAIXO.
app.get('/', (req, res) => {
res.send('Servidor funcionando, testando deploy automaticando qnd github atualiza');
});
app.use('/api', apiRouter);
app.use('/login', loginRouter);
app.use('/registrar', registrarRouter);
app.listen(PORT, () => {
console.log(`Acesse atraves de http://localhost:${PORT}`);
});
module.exports = connString;