forked from geshan/currency-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
24 lines (19 loc) · 782 Bytes
/
index.js
File metadata and controls
24 lines (19 loc) · 782 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
const express = require('express');
require('express-async-errors');
const expressUtils = require('expressjs-utils');
const bodyParser = require('body-parser');
const exchangeRates = require('./src/exchangeRates');
const app = express();
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));
});
expressUtils.hc(app);
expressUtils.static(app);
expressUtils.errorHandler(app);
expressUtils.start(app, 8080, 'dev');