-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (25 loc) · 822 Bytes
/
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
const express = require('express')
const path = require('path')
const socket = require('socket.io')
const axios = require('axios')
const bodyParser = require('body-parser')
const routes=require('./server/routes')
const mongoose = require('mongoose')
const app = express()
const port = process.env.PORT||3000
const server = app.listen(port, ()=>{
console.log('listening on port ' + port)
})
mongoose.connect('mongodb://localhost:27017/stocks')
const io = socket(server)
app.use(express.static(path.join(__dirname, 'client/public')))
app.use(function(req, res, next){
res.io = io;
next();
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(routes)
app.route('*').get((req,res)=>{
res.sendFile(path.join(__dirname, 'client/public/index.html'))
})