-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (36 loc) · 1.25 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
var express = require("express");
var app = express();
var parser = require("./models/parser.js");
var bodyParser = require("body-parser");
var url = process.env.FETCH_URL;
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
app.use(express.static('public'));
app.use('/views', express.static(__dirname + '/views'));
app.use('/controllers', express.static(__dirname + '/controllers'));
app.set('view engine', 'pug')
app.route("/").get(function (req, res) {
if(req.query.search){
var q = req.query.search;
parser.getData(url + q, function(data){
res.render('index', {data: data});
});
} else {
var data = {
'title': 'EksiEntries | Mainpage',
};
res.render('index', {'data' : data});
}
});
app.route("/api/entries").get(function (req, res) {
var newUrl = url + req.query.titleId + "/?p=" + req.query.p;
parser.getInfo(newUrl, function(info){
res.send(info);
});
});
app.listen(process.env.PORT, function () {
var date = new Date(Date.now());
var time = date.toLocaleTimeString('en-US', { hour12: false });
var day = date.toDateString();
console.log('Server listening :\n', 'Port:', process.env.PORT, 'Time :', day + ' ' + time);
});