-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (31 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
36
37
38
const express = require('express');
const axios = require('axios');
const { query, validationResult } = require('express-validator');
const app = express();
app.use(express.json());
app.get(
'/',
query('keyword')
.isString().trim().isLength({max: 255})
.withMessage('keyword may not exceed 255 characters'),
(req, res) => {
const keyword = req.query.keyword;
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(422).json({ errors: errors.array() });
}
axios.post('https://ivzeui0q5l.execute-api.us-east-1.amazonaws.com/default/assignment09', {keyword})
.then(result => res.send(result.data))
.catch(err => res.status(500).send(`Error: ${err}`));
}
);
// Catch-all for non-existent routes
app.get('*', function (req, res) {
res.statusCode = 404;
res.send();
});
app.listen(3000, function () {
const host = this.address().address;
const port = this.address().port;
console.log("Example app listening at http://%s:%s", host, port);
});