-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (29 loc) · 983 Bytes
/
server.js
File metadata and controls
37 lines (29 loc) · 983 Bytes
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
/**
* Created by logov on 16-Dec-16.
*/
var express = require('express'),
bodyParser = require('body-parser'),
path = require('path'),
app = express(),
//apiRouter = require('./api'),
siteRouter = require('./site');
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8080');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
next();
});
//app.use('/api', apiRouter);
app.use('/', siteRouter);
app.use(express.static(path.join(__dirname, 'site/public')));
require('express-ws')(app);
app.ws('/ws', function(ws, req) {
ws.on('message', function (msg) {
ws.send('Reply for message: "' + msg + '"')
});
});
let port = process.env.PORT || 8224;
app.listen(port);
console.log('Server started on port ' + port);