-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
30 lines (22 loc) · 820 Bytes
/
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
const express = require('express');
const bodyParser = require('body-parser');
const feedRoutes = require('./routes/feed');
const userRoutes = require('./routes/user');
const app = express();
app.use(bodyParser.json()) //application/json
//Headers for CORS Errors
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
next();
});
//set the routes
app.use('/feed', feedRoutes);
app.use('/user', userRoutes);
//set the port
app.set( 'port', ( process.env.PORT || 5000 ));
// Start node server
app.listen( app.get( 'port' ), function() {
console.log( 'Node server is running on port ' + app.get( 'port' ));
});