-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
94 lines (74 loc) · 2.24 KB
/
server.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var http=require('http')
var request = require('request');
const express = require('express');
const cors = require('cors');
const port=process.env.PORT || 3000
const app=express();
let bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
const API_KEY= process.env.Sub_KEY
app.use(cors());
app.use(express.static("ui"))
app.get("/",function(req,resp){
resp.send("Hello")
})
app.post("/getFaceData",function(req,resp){
var options={
uri:"https://eastus.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceAttributes=age,glasses,emotion",
body:req,
method:'POST',
headers:{
'Content-Type':'application/octet-stream',
'Ocp-Apim-Subscription-Key':API_KEY
}
}
request.post(options,(req,response)=>{
resp.send(JSON.parse(response.body))
})
})
app.get("/verify/:faceIds",cors(),function(req,resp){
console.log(req.params.faceIds)
let rbody={
"personGroupId":"wardbell",
"faceIds":[req.params.faceIds]
}
var options={
uri:"https://eastus.api.cognitive.microsoft.com/face/v1.0/identify",
body:rbody,
method:'POST',
headers:{
'Ocp-Apim-Subscription-Key':API_KEY
},
json:true
}
request.post(options,(reqs,response)=>{
resp.send(JSON.parse(JSON.stringify(response.body)))
//resp.send(false)
})
})
app.get("/verifyrohit/:faceIds",cors(),function(req,resp){
console.log(req.params.faceIds)
let rbody={
"faceId": req.params.faceIds,
"personId": "56b07d6d-784e-4240-8a81-e69b7d689785",
"personGroupId":"rohitramname"
}
var options={
uri:"https://eastus.api.cognitive.microsoft.com/face/v1.0/verify",
body:rbody,
method:'POST',
headers:{
'Ocp-Apim-Subscription-Key':API_KEY
},
json:true
}
request.post(options,(reqs,response)=>{
resp.send(JSON.parse(JSON.stringify(response.body)))
//resp.send(false)
})
})
app.listen(port, () => {
console.log('listening'+port.toString())
})
//app.listen(port,function(){console.log('server started')});