forked from Skyscanner/full-stack-recruitment-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (39 loc) · 1.29 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
42
43
44
45
46
47
/* eslint-disable no-console */
// Disabling 'no-console' as it's reasonable for this file to do some logging.
const express = require('express');
const app = express();
const livePricing = require('./live-pricing');
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
app.get('/', (req, res) => {
res.send('Hello World!');
});
/**
Simple flight search api wrapper.
TODO: client should provide params.
API params and location values are here:
http://business.skyscanner.net/portal/en-GB/Documentation/FlightsLivePricingQuickStart
*/
app.get('/api/search', async (req, res) => {
try {
const results = await livePricing.search({
/*
TODO: client to provide params.
Some params are already provided for you - see live-pricing.js.
Check API docs to see the other params you need to provide.
*/
});
// TODO - a better format for displaying results to the client
console.log('TODO: transform results for consumption by client');
res.json(results);
} catch (err) {
res.status(500).send(err);
console.error(err);
}
});
app.listen(4000, () => {
console.log('Node server listening on http://localhost:4000');
});