-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
56 lines (46 loc) · 1.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
var express = require('express');
var lessMiddleware = require('less-middleware');
var fs = require('fs');
var http = require('http');
var url = require('url');
var config = require('./config');
var api_model = __dirname + '/views/api_model.json';
var apipage = {};
var app = express();
app.engine('.html', require('ejs').__express);
app.set('views', __dirname + '/views');
app.set('view engine', 'html');
app.use(lessMiddleware({
src : __dirname + '/public',
compress : true
}));
/*
app.use(function(req, res, next) {
if(req.url.substr(-1) == '/' && req.url.length > 1)
res.redirect(301, req.url.slice(0, -1));
else
next();
});
*/
app.use(express.static(__dirname + '/public'));
fs.readFile(api_model, 'utf8', function (err, data) {
if (err) { console.log('Error: ' + err); return; }
apipage = JSON.parse(data);
console.log(apipage);
app.get('/', function(req, res) {
if(req.url === "/"){
console.log("root");
}
res.render('index', {
proxyUrl: config.proxyUrl,
page: apipage
});
});
app.get('/conferences/detroit2015', function(req,res){
res.status = 301;
res.redirect('/');
});
var port = process.env.PORT || 3000;
app.listen(port);
console.log('Listening on port %d', port);
});