-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (28 loc) · 1021 Bytes
/
Copy pathserver.js
File metadata and controls
34 lines (28 loc) · 1021 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
var express = require('express'),
app = express(),
bodyParser = require('body-parser'),
path = require('path'),
port = process.env.port || 8099,
customerRouter = require('./routes/customer.route'),
ignoredPaths = ['/static', '/api'];
app.use(express.static('public'));
app.use('/static', express.static(__dirname + '/node_modules'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.all('/*', function(req, res, next) {
//Redirecting to index only the requests that do not start with ignored paths
if(!startsWith(req.url, ignoredPaths))
res.sendFile('index.html', { root: path.resolve(__dirname, 'public') });
else
next();
});
app.use('/api/customers', customerRouter);
function startsWith(string, array) {
for(i = 0; i < array.length; i++)
if(string.startsWith(array[i]))
return true;
return false;
}
app.listen(port, function() {
console.log('Server running on http://localhost:' + port);
});