-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
51 lines (34 loc) · 1.19 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const express = require('express')
const bodyParser = require('body-parser')
const ejs = require('ejs')
var manager = require('./fetcher')
// initialize app
const app = express()
// set view engine for dynamic html generation
app.set("view engine", "ejs")
// set path for static files like css, js, images
app.use("/static", express.static('static'))
// create application/x-www-form-urlencoded parser
var urlencodedParser = bodyParser.urlencoded({ extended: false })
// render main page for request made on "/" page
app.get("/", function(req, res){
res.render("index", {result: ""})
// res.render("maintainence")
console.log("GET request made on '/'")
})
// handle POST requests
app.post("/", urlencodedParser, function(req, res) {
console.log("POST request made on '/'")
manager.fetchSubjectLink(req.body.code, function(data, subID) {
manager.fetchPaperLinks(data[0], req.body, subID, function(result) {
// console.log(result)
res.json(result)
})
})
})
// render 404 page for request made on any unspecified page
app.use(function(req, res) {
res.render('404', {})
})
// set port for server to listen
app.listen(process.env.PORT || 3000)