-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-server.js
More file actions
43 lines (39 loc) · 1.12 KB
/
test-server.js
File metadata and controls
43 lines (39 loc) · 1.12 KB
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
const http = require('http')
const fs = require('fs')
const util = require('util')
const readFile = util.promisify(fs.readFile)
http
.createServer(async (req, res) => {
switch (req.url) {
case '/wp-json/wplf/v2/submitForm': {
const json = JSON.stringify(require('./mocks/success.json'))
res.writeHead(200, {
'Content-Type': 'text/json',
'Access-Control-Allow-Origin': '*',
})
res.write(json)
res.end()
break
}
case '/wp-json/wplf/v2/getForm?form=215': {
const json = JSON.stringify(require('./mocks/form.json'))
res.writeHead(200, {
'Content-Type': 'text/json',
'Access-Control-Allow-Origin': '*',
})
res.write(json)
res.end()
break
}
default: {
res.writeHead(400, {
'Content-Type': 'text/html',
'Access-Control-Allow-Origin': '*',
})
res.write('<h1>Nothing to serve</h1>')
}
}
})
.listen(8089)
setTimeout(() => process.exit(0), 5000) // Kill mock server after 5 seconds
// Alternatively start server from tests