-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·83 lines (62 loc) · 2.07 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const config = require('./config.js');
const middleware = require('./middleware/middleware.js');
const app = express();
const evolveRoutes = require('./backend/routes/evolving.js');
const writingRoutes = require('./backend/routes/write-image.js');
const trashRoutes = require('./backend/routes/programs/trash.js');
const recognizeRoutes = require('./backend/routes/programs/recognize.js');
const get = require('./backend/evolve-app/data/get/get.js');
// console.log("livereload", config.livereloadPort);
var PORTS = {
heroku: 8080,
http: 80,
livereload: config.livereloadPort,
misc1: 3000,
misc2: 4200,
misc3: 4210,
};
app.use(middleware.refresh());
if (process.env.NODE_ENV == 'production') app.use(middleware.forceSSL());
else {
console.log('environment development');
}
app.use(bodyParser.urlencoded({ extended: 'true' })); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' }));
app.use('/evolve', evolveRoutes);
app.use('/write', writingRoutes);
app.use('/trash', trashRoutes);
app.use('/recognize', recognizeRoutes);
if (process.env.NODE_ENV != 'production') {
app.use(
require('connect-livereload')({
port: PORTS.livereload,
})
);
}
// app.use(express.static(path.join(__dirname, "dist", "assets")));
app.use('/url', function (req, res, next) {
// var port = currentPort == 3000 ? ':3000' : '';
var host = req.get('host');
console.log('host is:', host);
res.send({ host: host });
});
app.use('/', express.static(path.join(__dirname, 'dist')));
app.use(middleware.errorHandler());
var env = process.env.NODE_ENV;
var port;
if (process.env.PORT) {
port = process.env.PORT;
} else if (env == 'production') {
port = PORTS.heroku;
} else if (env == 'development') {
port = PORTS.misc2;
} else {
port = PORTS.misc1;
}
var listener = app.listen(port, function () {
console.log('listening on port', listener.address().port);
});