forked from nihgwu/iZhihu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (28 loc) · 878 Bytes
/
app.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
var express = require('express');
var favicon = require('serve-favicon');
var path = require('path');
var http = require('http');
var config = require('./config');
var router = require('./lib/router');
var crawler = require('./lib/crawler');
var app = express();
global.config = config;
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(favicon('favicon.ico'));
app.use(express.static(path.join(__dirname, 'public')));
app.locals.config = config;
app.locals.isActive = function isActive(url, link) {
if (link == '/' && url != '/') return "";
return url.indexOf(link) === 0 ? "active" : "";
};
app.use(function (req, res, next) {
res.locals.url = req.url;
next();
});
app.use('/', router);
app.use(function (req, res, next) {
res.status(404).render('error');
});
app.listen(process.env.PORT || config.port);
crawler.run();