-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontroller.js
33 lines (26 loc) · 1.06 KB
/
controller.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
const crawlTJAL = require("./crawler_tjal/crawlTjal")
const crawlTJMS = require("./crawler_tjms/crawlTjms")
function controller(code, response){
if(code.includes(".8.12.")){
crawlTJMS(code).then(resp=>{
response.writeHead(200,{'Content-Type': 'application/json'});
response.end(JSON.stringify(resp))
}).catch(err =>{
console.log(err)
response.writeHead(400,{'Content-Type': 'application/json'});
response.end(`{"error": "${http.STATUS_CODES[404]}"}`)
})
}else if(code.includes(".8.02.")){
crawlTJAL(code).then(resp=>{
response.writeHead(200,{'Content-Type': 'application/json'});
response.end(JSON.stringify(resp))
}).catch(err => {
console.log(err)
response.writeHead(400,{'Content-Type': 'application/json'});
response.end(`{"error": "${http.STATUS_CODES[404]}"}`)
})
}else{
response.end(`{"error": "${http.STATUS_CODES[404]}"}`)
}
}
module.exports = controller;