-
Notifications
You must be signed in to change notification settings - Fork 20
/
server.js
executable file
·39 lines (30 loc) · 1.18 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
var fs = require('fs-extra');
var path = require('path');
var request = require('request');
var express = require('express');
var rewrite = require('express-urlrewrite');
var bodyParser = require('body-parser');
var serverAPI = require('./server/api');
var app = express();
app.set('port', (process.env.PORT || 3000));
serverAPI.setCurrentWorkingDirPath(path.join(__dirname, 'server'));
app.get('/api/readData', function(req, res){
serverAPI.readDataFile()
.then( function(response){
response = response || {};
res.send(response);
})
.catch( function(err){
var errorMessage = err.message ? err.message : err;
res.writeHead(500, errorMessage);
res.end(errorMessage);
});
});
// Routes for real application with React-Router
app.use('/resources', express.static(path.join(__dirname, 'public/resources')));
app.use('/images', express.static(path.join(__dirname, 'public/images')));
app.use(rewrite('/*', '/index.html'));
app.use('/', express.static(path.join(__dirname, 'public')));
app.listen(app.get('port'), function() {
console.log('Server started: http://localhost:' + app.get('port') + '/');
});