-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
60 lines (47 loc) · 1.47 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var PORT = process.env.PORT || 5000;
var ENV = process.env.NODE_ENV;
// setup http + express + socket.io
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server, {
'log level': 0
});
// To resolve socket.io handshake bug :
io.set("transports", ["xhr-polling"]);
// Because we are behind Apache Proxy :
app.enable('trust proxy');
require('deployd').attach(
server, {
socketIo: io, // if not provided, attach will create one for you.
env: ENV,
db: {
host: 'localhost',
port: 35683,
name: 'name',
credentials: {
username: 'username',
password: 'password'
}
}
}
);
var dpdRoutes = ["dashboard", "__resources", "links"];
//send our main angular html file if any link without dot is requested, e.g. 'http://someurl/about'
//this is our actual server side redirect, we don't send index.html when there's dot in link assuming such a request
//is for static data like .js, .css or .html
app.get('/[^\.]+$', function(req, res, next) {
var first_path = req.path.split('/');
if (dpdRoutes.indexOf(first_path[1]) > -1) // dpd requests
{
return next();
} else // angular requests
{
res.sendfile("index.html", {
root: __dirname + '/public'
});
}
});
app.use(server.handleRequest);
// start server
server.listen(PORT);