-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (35 loc) · 1.14 KB
/
app.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
43
44
45
46
47
48
49
/**
* Created by Tomás on 03-11-2018.
*/
'use strict';
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
const server = require('http').createServer(app);
const socket = require('./socketIO');
app.use(cors());
// Start socketIO
socket.startScocket(server);
app.use((req, res, next) =>{
res.header('Access-Control-Allow-Origin','*');
res.header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS');
res.header('Allow', 'GET, POST, OPTION, PUT, DELETE');
next();
});
//middleware bodyparser
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
//load routes
const user_routes = require('./server/routes/User');
// Angular DIST output folder
app.use(express.static(path.join(__dirname, 'dist')));
//Base Route
app.use('/api/user', user_routes);
// Send all other requests to the Angular app
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
module.exports = server;