-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
64 lines (56 loc) · 1.63 KB
/
app.js
File metadata and controls
64 lines (56 loc) · 1.63 KB
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
const path = require("path");
const functions = require("./src/lib/functions")
const express = require("express");
const winston = require('winston');
const expressWinston = require('express-winston');
const app = express();
const port = process.env.PORT || "8000";
app.set("views", path.join(__dirname, "views"));
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(express.static(path.join(__dirname, "public")));
app.use(expressWinston.logger({
transports: [
new winston.transports.Console()
],
format: winston.format.combine(
winston.format.colorize(),
winston.format.json()
),
expressFormat: true, // Use the default Express/morgan request formatting.
// Enabling this will override any msg if true.
// Will only output colors with colorize set to true
colorize: true,
ignoreRoute: function (req, res) { return true; }
}));
app.use(expressWinston.errorLogger({
transports: [
new winston.transports.Console()
],
format: winston.format.combine(
winston.format.colorize(),
winston.format.json()
)
}));
app.use(express.json());
app.get("/", function (req, res) {
res.render("index", {});
});
app.get("/findTitle", function(req, res) {
let title = req.query.title;
let postcode = req.query.postcode;
if (!title) {
res.status(400).send('Missing title parameter')
return false;
}
functions.getData(title, true)
.then(function(resp) {
return res.json((JSON.parse(resp) ?? {}));
})
.catch(function (err) {
return res.status(500).send(err.message);
});
})
app.listen(port, () => {
console.log(`Listening to requests on http://localhost:${port}`);
})