-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-req.js
More file actions
42 lines (33 loc) · 975 Bytes
/
test-req.js
File metadata and controls
42 lines (33 loc) · 975 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
const ObjectPath = require("object-path");
const config = {
name: "home1",
host: "https://b2ads.ad5track.com",
path: "/ad_products/top",
method: "GET",
properties: [
{ from: "headers.referrer", to: "query.referrer" },
{ from: "query.size" , to: "query.limit"},
{ from: "query.userId" , to: "query.user_id" , middleware: [ "parseInt" ] },
{ value: "json" , to: "query.t" },
{ from: "query.terms", to: "query.q", middleware: [ "threeFirstWords" ] },
{ from: "query.type", to: "query.type", required: true }
]
}
const request = {
headers: {
referrer: "http://www.americanas.com"
},
query: {
size: 10,
userId: "30",
terms: "notebook asus 16gb blabla bla",
type: "supplier"
}
}
const newRequest = {}
config.properties.forEach(prop => {
const { to, value, from } = prop
const value2 = from ? ObjectPath.get(request, from) : value
ObjectPath.set(newRequest, to, value2)
console.log(newRequest)
})