-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (34 loc) · 1.33 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
require('./config');
const http = require('http');
const https = require('https');
const morgan = require('morgan');
const fs = require("fs");
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
const app = express();
function config(){
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET, POST PUT, DELETE, OPTIONS');
res.header('Access-Control-Allow-Header', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, Access-Control-Allow-Credentials');
res.header('Access-Control-Allow-Credentials', 'true');
res.header("Access-Control-Allow-Headers: Authorization");
next();
});
}
config();
app.use(cors())
app.use(require('./router'));
app.use(express.static('client'));
var httpServer = http.createServer(app);
var httpsServer = https.createServer(options, app);
httpServer.listen(process.env.PORT, () => console.log(`Escuchando en el puerto ${process.env.PORT}!`));
httpsServer.listen(3002, () => console.log(`Escuchando en el puerto 3002!`));