-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (33 loc) · 1019 Bytes
/
server.js
File metadata and controls
44 lines (33 loc) · 1019 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
38
39
40
41
42
const amazon = require('amazon-product-api')
const mongoose = require('mongoose')
const express = require('express')
const keys = require('./config/keys');
const cors = require('cors')
require('./models/Users');
const bodyParser = require('body-parser')
const secret = require('./client/src/actions/secret')
mongoose.connect(keys.mongoURI)
const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
extended: true
}))
app.use(cors())
const client = amazon.createClient({
awsTag: secret.associateTag,
awsId: secret.accessId,
awsSecret: secret.secret
});
app.get('/amazon/:index', async (req, res) => {
var products = await client.itemSearch({
keywords: req.query.title,
searchIndex: req.params.index,
condition: req.params.condition,
responseGroup: 'EditorialReview,ItemAttributes,OfferFull,Images,Similarities'
})
res.send(products);
});
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log('Node.js listening on port ' + PORT)
})