-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.config.js
More file actions
37 lines (32 loc) · 968 Bytes
/
http.config.js
File metadata and controls
37 lines (32 loc) · 968 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
/* eslint-disable no-console */
const { readFileSync } = require('fs');
const path = require('path');
const { IncomingForm } = require('formidable');
module.exports = {
hostname: 'localhost',
port: '3011',
webPath: path.join(__dirname, 'dist'),
mockPath: __dirname,
logLevel: 'debug',
mocks: {
'/submit.html': {
post: function(request, response) {
const form = new IncomingForm();
const { headers } = request;
// Inspect
console.log('headers: ', headers);
form.parse(request, (err, fields) => {
console.log('fields: ', fields); // ES
let output = null;
if (fields['test']) {
output = readFileSync(path.join(__dirname, 'test/fixtures/success.html'));
} else {
output = readFileSync(path.join(__dirname, 'test/fixtures/error.html'));
}
// Send response
response.send(output);
});
}
}
}
};