-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
35 lines (29 loc) · 1.08 KB
/
index.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
const express = require('express');
require('express-async-errors');
const expressUtils = require('expressjs-utils');
const bodyParser = require('body-parser');
const helmet = require('helmet');
const exchangeRates = require('./src/exchangeRates');
const app = express();
app.use(helmet());
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.json({
message: `Please hit the api like: /api/convert/fromCurrency/toCurrency/onDate
example: ${req.get('host')}/api/convert/USD/AUD/${new Date().toISOString().split('T')[0]}`,
});
});
app.get('/api/convert/:fromCurrency/:toCurrency/:onDate?', async (req, res) => {
console.log(`Api hit`, req.params);
res.json(await exchangeRates.get(req.params));
});
app.get('/api/rates', async (req, res) => {
res.json(await exchangeRates.getMultiple(req.query.page || 1));
});
app.get('/api/rates/:currency', async (req, res) => {
res.json(await exchangeRates.getByToCurrency(req.query.page || 1, req.params.currency));
});
expressUtils.hc(app);
expressUtils.static(app);
expressUtils.errorHandler(app);
expressUtils.start(app, 8080, 'dev');