-
Notifications
You must be signed in to change notification settings - Fork 0
/
www
37 lines (29 loc) · 1.07 KB
/
www
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
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const http = require('http');
const app = express();
// API Routes locations
const api = require('./routes/api');
// Parsers
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(function(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-Headers", "Origin, X-Requested- With, Content-Type, Accept");
next();
});
// Angular DIST output folder
app.use(express.static(path.join(__dirname, 'dist')));
// Call API location
app.use('/api', api);
// Send all other requests to the Angular app
// app.get('*', (req, res) => {
// res.sendFile(path.join(__dirname, './dist/index.html'));
// });
// Setting Port Server
const port = process.env.PORT || '3000';
app.set('port', port);
const server = http.createServer(app);
server.listen(port, () => console.log(`Server running on localhost:${port}`));