forked from forter/popshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
58 lines (49 loc) · 1.39 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
'use strict'
const express = require('express')
const cookieParser = require('cookie-parser')
const multer = require('multer')
const request = require('request-promise-native')
function getForterToken(req) {
// TODO: impelement
// see http://expressjs.com/en/api.html#req.cookies
return ''
}
function createAuth() {
// TODO: implement
// see https://github.com/request/request#http-authentication
return {}
}
function createHeaders() {
// TODO: impelement
// Use the headers from step 1
return {}
}
function createOrder(id, forterToken, inputs) {
// TODO: impelement
// Use the request body from step 1
return {}
}
async function sendToForter(forterToken, inputs) {
const id = 'TEST'
const auth = createAuth()
const headers = createHeaders()
const json = createOrder(id, forterToken, inputs)
const {action} = await request.post(`https://api.forter-secure.com/v2/orders/${id}`, {auth, headers, json})
return action
}
const app = express()
app.use(cookieParser())
app.use(express.static('static'))
app.post('/order', multer().none(), async (req, res) => {
try {
const forterToken = getForterToken(req)
const decision = await sendToForter(forterToken, req.body)
res.json({status: 'success', decision})
} catch (err) {
console.error('error: %s', err.message)
res.json({status: 'error'})
}
})
app.listen(8080, () => {
console.log('listening on port 8080')
})