-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (30 loc) · 963 Bytes
/
index.js
File metadata and controls
37 lines (30 loc) · 963 Bytes
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
const express = require('express');
const app = express();
const PORT = 4000;
const scraper = require('./pcc_modules/scraper.js');
const parser = require('./pcc_modules/parser.js');
const cors = require('cors');
app.use(cors());
/*
app.use(cors({
origin: 'https://github.com/newwby/newwby.github.io'
// }));
*/
// handling for legacy
app.get('/home', async (req, res) => {
res.redirect('/?' + new URLSearchParams(req.query).toString());
});
app.get('/', async (req, res) => {
const postcode = req.query.postcode
if (postcode) {
const pcc_code_output = await scraper.get_code(postcode, true)
const parsed_output = parser.parseScraperOutput(pcc_code_output)
res.status(200).send(`${parsed_output}`);
} else {
res.status(400).send('Welcome, your app is working well, but you forgot to include a postcode.');
}
});
app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});
module.exports = app;