-
Notifications
You must be signed in to change notification settings - Fork 11
/
es-dev-server.config.js
78 lines (76 loc) · 2.56 KB
/
es-dev-server.config.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
// Also run the websocket server now
require('./websocket-server.js');
module.exports = {
port: 8090,
watch: true,
nodeResolve: true,
appIndex: './index.html',
plugins: [
{
transform(context) {
context.response.set('Access-Control-Allow-Origin', 'http://localhost:8080');
return {
body: context.body,
};
},
serve(context) {
console.log('context path ', context);
if (context.originalUrl === '/login') {
console.log('>>>> context ', context);
context.response.status = 200;
return { body: 'success', type: 'text' };
}
if (context.originalUrl === '/submission1') {
console.log('>>>> context ', context);
context.response.status = 200;
return { body: '<data></data>', type: 'xml' };
}
if (context.originalUrl === '/submission2?foo=bar¶m2=value2') {
const foo = context.URL.searchParams.get('foo');
const param = context.URL.searchParams.get('param2');
context.response.status = 200;
return {
body: `Params received: <ul><li>foo=${foo}</li><li>param2=${param}</li></ul>`,
type: 'text',
};
}
if (context.originalUrl === '/submission2') {
// console.log('>>>> context ', context);
context.response.status = 200;
return { body: '<data><greeting>Hi from response</greeting></data>', type: 'xml' };
}
if (context.originalUrl === '/submission2?foo=bar') {
// console.log('>>>> context ', context);
context.response.status = 200;
return {
body: '<data><greeting>Hi from response - got params</greeting></data>',
type: 'xml',
};
}
if (context.originalUrl === '/submissionfails') {
// console.log('>>>> context ', context);
context.response.status = 200;
return { body: '<data>', type: 'xml' };
}
if (context.originalUrl === '/replaceall') {
// console.log('>>>> context ', context);
context.response.status = 200;
return {
body: '<div>Thanks for being here</div>',
type: 'html',
};
}
if (context.originalUrl === '/redirect') {
// console.log('>>>> context ', context);
context.response.status = 200;
return {
body: '/index.html',
type: 'text',
};
}
return null;
},
},
],
moduleDirs: ['node_modules', 'web_modules'],
};