-
Notifications
You must be signed in to change notification settings - Fork 7
/
server.js
79 lines (67 loc) · 2.24 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
require('babel-register')
var compression = require("compression");
var config = require("config");
var express = require("express");
var debug = require("debug")("server");
var favicon = require("serve-favicon");
var logger = require("morgan");
var methodOverride = require("method-override");
var bodyParser = require("body-parser");
var errorHandler = require("./middleware/error-handler").errorHandler;
var consolidate = require("consolidate");
var path = require("path");
var activityRoutes = require("./routes/activity").router;
var corpora = require("./lib/corpora");
var corpusRoutes = require("./routes/corpus").router;
var userRoutes = require("./routes/user").router;
var siteRoutes = require("./routes/site").router;
var reduxRender = require("./routes/react-render").reduxRender;
var acceptSelfSignedCertificates = {
strictSSL: false
};
if (process.env.NODE_ENV === "production") {
acceptSelfSignedCertificates = {};
}
if (config.offline) {
var requestSampleData = require('./config/offline').requestSampleData;
requestSampleData(config);
}
var app = express();
// configure Express
app.engine("html", consolidate.handlebars);
app.set("view engine", ".html");
app.set("views", path.join(__dirname, "views"));
app.use(favicon(__dirname + "/public/favicon.ico"));
app.use(logger("combined"));
app.use(methodOverride());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(express.static(path.join(__dirname, "public")));
app.use(compression())
if (process.env.NODE_ENV === "production") {
app.use(express.static(path.join(__dirname, "dist", "public")))
} else {
app.use("/assets", express.static(path.join(__dirname, "app", "assets")))
app.use(express.static(path.join(__dirname, "dist")))
}
/*
* Routes
*/
app.use('/', siteRoutes);
app.get('/api/corpora', function(req, res, next) {
corpora.getAllCorpora().then(function(results) {
res.json(results);
}, next).catch(next)
});
app.use('/api/activity', activityRoutes);
app.use('/api/users', userRoutes);
app.use('/api', corpusRoutes);
app.use('/search', function(req, res, next) {
res.redirect('/corpora');
});
app.get("*", reduxRender);
// error handling middleware should be loaded after the loading the routes
app.use(errorHandler);
module.exports = app;