-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (33 loc) · 1.05 KB
/
server.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
import express from 'express';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import routes from './src/routes/messageRoutes';
const app = express();
const PORT = process.env.PORT || 5050;
//fix cross origin if not remove if causing problems
app.use( (req, res, next) =>{
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
})
// mongoose connection
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://admin:[email protected]:51720/websitemessagedb', {
useMongoClient: true
}).then( () => {
console.log('connected succesfully');
}, err => {
console.log(`err`);
});
// bodyparser setup
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
routes(app);
// serving static files
app.use(express.static('public'));
app.get('/', (req, res) =>
res.send(`Node and express server is running on port ${PORT}`)
);
app.listen(PORT, () =>
console.log(`your server is running on port ${PORT}`)
);