barehttp 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +185 -28
- package/lib/context/execution.d.ts +7 -0
- package/lib/context/execution.js +14 -0
- package/lib/context/index.d.ts +10 -0
- package/lib/context/index.js +46 -0
- package/lib/env.d.ts +5 -0
- package/lib/env.js +5 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +3 -0
- package/lib/logger/index.d.ts +16 -0
- package/lib/logger/index.js +26 -0
- package/lib/logger/serializers.d.ts +28 -0
- package/lib/logger/serializers.js +78 -0
- package/lib/middlewares/cookies/cookie-manager.d.ts +25 -0
- package/lib/middlewares/cookies/cookie-manager.js +68 -0
- package/lib/middlewares/cookies/signer.d.ts +8 -0
- package/lib/middlewares/cookies/signer.js +25 -0
- package/lib/middlewares/cors/cors.d.ts +38 -0
- package/lib/middlewares/cors/cors.js +164 -0
- package/lib/request.d.ts +84 -0
- package/lib/request.js +260 -0
- package/lib/schemas/custom-schema.d.ts +32 -0
- package/lib/schemas/custom-schema.js +62 -0
- package/lib/schemas/dirty-tsm.d.ts +1 -0
- package/lib/schemas/dirty-tsm.js +199 -0
- package/lib/schemas/generator.d.ts +7 -0
- package/lib/schemas/generator.js +179 -0
- package/lib/schemas/helpers.d.ts +27 -0
- package/lib/schemas/helpers.js +40 -0
- package/lib/schemas/json-schema.d.ts +2 -0
- package/lib/schemas/json-schema.js +48 -0
- package/lib/schemas/openami-schema.d.ts +2 -0
- package/lib/schemas/openami-schema.js +59 -0
- package/lib/schemas/project.d.ts +1 -0
- package/lib/schemas/project.js +1 -0
- package/lib/server.d.ts +154 -0
- package/lib/server.js +396 -0
- package/lib/utils/content-type.d.ts +54 -0
- package/lib/utils/content-type.js +54 -0
- package/lib/utils/http-methods.d.ts +11 -0
- package/lib/utils/http-methods.js +9 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +4 -0
- package/lib/utils/safe-json.d.ts +2 -0
- package/lib/utils/safe-json.js +18 -0
- package/lib/utils/status-codes.d.ts +339 -0
- package/lib/utils/status-codes.js +339 -0
- package/lib/utils/status-phrases.d.ts +338 -0
- package/lib/utils/status-phrases.js +339 -0
- package/lib/websocket.d.ts +36 -0
- package/lib/websocket.js +176 -0
- package/package.json +64 -32
- package/.eslintrc.js +0 -47
- package/.github/workflows/release.yml +0 -27
- package/.jest-setup.js +0 -1
- package/jest.config.js +0 -8
- package/prettier.config.js +0 -6
- package/src/context/context.test.ts +0 -30
- package/src/context/execution.ts +0 -17
- package/src/context/index.ts +0 -61
- package/src/env.ts +0 -5
- package/src/examples/bare-http.ts +0 -36
- package/src/examples/express.ts +0 -11
- package/src/examples/fastify.ts +0 -18
- package/src/index.ts +0 -4
- package/src/logger/index.ts +0 -67
- package/src/logger/serializers.test.ts +0 -186
- package/src/logger/serializers.ts +0 -109
- package/src/middlewares/cookies/cookie-manager.ts +0 -86
- package/src/middlewares/cookies/signer.ts +0 -30
- package/src/report.ts +0 -25
- package/src/request.test.ts +0 -143
- package/src/request.ts +0 -277
- package/src/server.integration.test.ts +0 -296
- package/src/server.middlewares.test.ts +0 -93
- package/src/server.routes.test.ts +0 -71
- package/src/server.ts +0 -450
- package/src/utils/content-type.ts +0 -59
- package/src/utils/index.ts +0 -2
- package/src/utils/safe-json.ts +0 -17
- package/src/utils/status-codes.ts +0 -339
- package/src/utils/status-phrases.ts +0 -339
- package/tsconfig.json +0 -24
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
import { context } from './context';
|
|
4
|
-
import { BareServer } from './server';
|
|
5
|
-
|
|
6
|
-
test('Enables statistics report', async () => {
|
|
7
|
-
const app = new BareServer({ statisticReport: true });
|
|
8
|
-
await app.start();
|
|
9
|
-
|
|
10
|
-
const { data } = await axios.get('http://localhost:3000/_report');
|
|
11
|
-
await app.stop();
|
|
12
|
-
|
|
13
|
-
expect(data).toContain(
|
|
14
|
-
'<!DOCTYPE html><html><head><title>Routes usage</title><meta charset="utf-8"></head>',
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('Statistics report sum up with a route hit', async () => {
|
|
19
|
-
const app = new BareServer({ statisticReport: true });
|
|
20
|
-
await app.start();
|
|
21
|
-
|
|
22
|
-
await axios.get('http://localhost:3000/_report');
|
|
23
|
-
const { data } = await axios.get('http://localhost:3000/_report');
|
|
24
|
-
await app.stop();
|
|
25
|
-
|
|
26
|
-
expect(data).toContain('<td>GET /_report</td><td>2</td>');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('Statistics report sum up with a route fail hit', async () => {
|
|
30
|
-
const app = new BareServer({ statisticReport: true });
|
|
31
|
-
app.route.get({
|
|
32
|
-
route: '/test',
|
|
33
|
-
handler: () => {
|
|
34
|
-
throw new Error();
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
await app.start();
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
await axios.get('http://localhost:3000/test');
|
|
42
|
-
} catch (e) {}
|
|
43
|
-
const { data } = await axios.get('http://localhost:3000/_report');
|
|
44
|
-
await app.stop();
|
|
45
|
-
|
|
46
|
-
expect(data).toContain('<td>GET /test</td><td>1</td><td>0</td><td>1</td>');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('Enables context in the settings', async () => {
|
|
50
|
-
const app = new BareServer({ context: true });
|
|
51
|
-
|
|
52
|
-
app.route.get({
|
|
53
|
-
route: '/test',
|
|
54
|
-
handler: () => !!context.current && context.current.store instanceof Map,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
await app.start();
|
|
58
|
-
const { data } = await axios.get('http://localhost:3000/test');
|
|
59
|
-
await app.stop();
|
|
60
|
-
|
|
61
|
-
expect(data).toBeTruthy();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('Enables cookies decoding in the settings', async () => {
|
|
65
|
-
const app = new BareServer({ cookies: true });
|
|
66
|
-
const spyCookies = jest.fn();
|
|
67
|
-
app.route.get({
|
|
68
|
-
route: '/test',
|
|
69
|
-
handler: (flow) => spyCookies(flow.getCookies()),
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
await app.start();
|
|
73
|
-
await axios.get('http://localhost:3000/test', {
|
|
74
|
-
headers: { cookie: 'myCookie=someValue; otherCookie=otherValue;' },
|
|
75
|
-
});
|
|
76
|
-
await app.stop();
|
|
77
|
-
|
|
78
|
-
expect(spyCookies).toHaveBeenCalledWith({ myCookie: 'someValue', otherCookie: 'otherValue' });
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('Enables cookies attachment in the settings', async () => {
|
|
82
|
-
const app = new BareServer({ cookies: true });
|
|
83
|
-
|
|
84
|
-
app.route.get({
|
|
85
|
-
route: '/test',
|
|
86
|
-
handler: (flow) =>
|
|
87
|
-
flow.cm?.setCookie('important', 'cookie', {
|
|
88
|
-
domain: 'example.com',
|
|
89
|
-
expires: new Date(),
|
|
90
|
-
path: '/',
|
|
91
|
-
}),
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
await app.start();
|
|
95
|
-
const { headers } = await axios.get('http://localhost:3000/test');
|
|
96
|
-
await app.stop();
|
|
97
|
-
|
|
98
|
-
expect(headers['set-cookie'][0]).toContain(
|
|
99
|
-
'important=cookie; Domain=example.com; Path=/; Expires=',
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test('Sets x-processing-time to milliseconds', async () => {
|
|
104
|
-
const app = new BareServer({ requestTimeFormat: 'ms' });
|
|
105
|
-
|
|
106
|
-
app.route.get({
|
|
107
|
-
route: '/test',
|
|
108
|
-
handler: () => {},
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
await app.start();
|
|
112
|
-
const { headers } = await axios.get('http://localhost:3000/test');
|
|
113
|
-
await app.stop();
|
|
114
|
-
|
|
115
|
-
expect(headers['x-processing-time-mode']).toBe('milliseconds');
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test('Base x-processing-time is in seconds', async () => {
|
|
119
|
-
const app = new BareServer();
|
|
120
|
-
|
|
121
|
-
app.route.get({
|
|
122
|
-
route: '/test',
|
|
123
|
-
handler: () => {},
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
await app.start();
|
|
127
|
-
const { headers } = await axios.get('http://localhost:3000/test');
|
|
128
|
-
await app.stop();
|
|
129
|
-
|
|
130
|
-
expect(headers['x-processing-time-mode']).toBe('seconds');
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test('Check that app started at the indicated port', async () => {
|
|
134
|
-
const app = new BareServer({ serverPort: 9999, statisticReport: true });
|
|
135
|
-
|
|
136
|
-
await app.start();
|
|
137
|
-
const { status } = await axios.get('http://localhost:9999/_report');
|
|
138
|
-
await app.stop();
|
|
139
|
-
|
|
140
|
-
expect(status).toBe(200);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// test returns of the data types
|
|
144
|
-
test('Server correctly classifies Buffer', async () => {
|
|
145
|
-
const app = new BareServer();
|
|
146
|
-
|
|
147
|
-
app.route.get({
|
|
148
|
-
route: '/test',
|
|
149
|
-
handler: () => {
|
|
150
|
-
return Buffer.from('text_data');
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
await app.start();
|
|
155
|
-
const { data } = await axios.get('http://localhost:3000/test');
|
|
156
|
-
await app.stop();
|
|
157
|
-
|
|
158
|
-
expect(data).toEqual('text_data');
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
test('Server correctly classifies JSON response', async () => {
|
|
162
|
-
const app = new BareServer();
|
|
163
|
-
|
|
164
|
-
app.route.get({
|
|
165
|
-
route: '/test',
|
|
166
|
-
handler: () => {
|
|
167
|
-
return { json: 'data', in: ['here'] };
|
|
168
|
-
},
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
await app.start();
|
|
172
|
-
const { data } = await axios.get('http://localhost:3000/test');
|
|
173
|
-
await app.stop();
|
|
174
|
-
|
|
175
|
-
expect(data).toEqual({ json: 'data', in: ['here'] });
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
test('Server correctly classifies Number response', async () => {
|
|
179
|
-
const app = new BareServer();
|
|
180
|
-
|
|
181
|
-
app.route.get({
|
|
182
|
-
route: '/test',
|
|
183
|
-
handler: () => {
|
|
184
|
-
return 123456;
|
|
185
|
-
},
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
await app.start();
|
|
189
|
-
const { data } = await axios.get('http://localhost:3000/test');
|
|
190
|
-
await app.stop();
|
|
191
|
-
expect(data).toEqual(123456);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test('Server correctly classifies incoming text/plain', async () => {
|
|
195
|
-
const app = new BareServer();
|
|
196
|
-
|
|
197
|
-
app.route.post({
|
|
198
|
-
route: '/test',
|
|
199
|
-
handler: (flow) => {
|
|
200
|
-
expect(flow.requestBody).toBe('text_data');
|
|
201
|
-
return 123456;
|
|
202
|
-
},
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
await app.start();
|
|
206
|
-
const { data } = await axios.post('http://localhost:3000/test', 'text_data', {
|
|
207
|
-
headers: { 'content-type': 'text/plain' },
|
|
208
|
-
});
|
|
209
|
-
await app.stop();
|
|
210
|
-
expect(data).toEqual(123456);
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
test('Server correctly classifies incoming application/json', async () => {
|
|
214
|
-
const app = new BareServer();
|
|
215
|
-
|
|
216
|
-
app.route.post({
|
|
217
|
-
route: '/test',
|
|
218
|
-
handler: (flow) => {
|
|
219
|
-
expect(flow.requestBody).toEqual({ json: 'json_data' });
|
|
220
|
-
return 'ok';
|
|
221
|
-
},
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
await app.start();
|
|
225
|
-
const { data } = await axios.post(
|
|
226
|
-
'http://localhost:3000/test',
|
|
227
|
-
{ json: 'json_data' },
|
|
228
|
-
{ headers: { 'content-type': 'application/json' } },
|
|
229
|
-
);
|
|
230
|
-
await app.stop();
|
|
231
|
-
expect(data).toEqual('ok');
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
test('Server correctly classifies incoming application/x-www-form-urlencoded', async () => {
|
|
235
|
-
const app = new BareServer();
|
|
236
|
-
|
|
237
|
-
app.route.post({
|
|
238
|
-
route: '/test',
|
|
239
|
-
handler: (flow) => {
|
|
240
|
-
expect(flow.requestBody).toEqual({ urlencoded: 'data', with: 'multiple_fields' });
|
|
241
|
-
return 'ok';
|
|
242
|
-
},
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
await app.start();
|
|
246
|
-
const { data } = await axios.post(
|
|
247
|
-
'http://localhost:3000/test',
|
|
248
|
-
'urlencoded=data&with=multiple_fields',
|
|
249
|
-
{ headers: { 'content-type': 'application/x-www-form-urlencoded' } },
|
|
250
|
-
);
|
|
251
|
-
await app.stop();
|
|
252
|
-
expect(data).toEqual('ok');
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
test('Server correctly classifies incoming any type', async () => {
|
|
256
|
-
const app = new BareServer();
|
|
257
|
-
|
|
258
|
-
app.route.post({
|
|
259
|
-
route: '/test',
|
|
260
|
-
handler: (flow) => {
|
|
261
|
-
expect(flow.requestBody.toString()).toEqual('this_is_buffered_text');
|
|
262
|
-
return 'ok';
|
|
263
|
-
},
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
await app.start();
|
|
267
|
-
const { data } = await axios.post('http://localhost:3000/test', 'this_is_buffered_text', {
|
|
268
|
-
headers: { 'content-type': 'application/octet-stream' },
|
|
269
|
-
});
|
|
270
|
-
await app.stop();
|
|
271
|
-
expect(data).toEqual('ok');
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
test('Server correctly aborts on long call with a per-route timeout set', async () => {
|
|
275
|
-
const app = new BareServer();
|
|
276
|
-
|
|
277
|
-
const wait = () => new Promise((res) => setTimeout(res, 3000));
|
|
278
|
-
app.route.post({
|
|
279
|
-
route: '/test',
|
|
280
|
-
options: { timeout: 2000 },
|
|
281
|
-
handler: async () => {
|
|
282
|
-
await wait();
|
|
283
|
-
return 'ok';
|
|
284
|
-
},
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
await app.start();
|
|
288
|
-
|
|
289
|
-
const { status } = await axios.post(
|
|
290
|
-
'http://localhost:3000/test',
|
|
291
|
-
{ json: 'json_data' },
|
|
292
|
-
{ validateStatus: () => true },
|
|
293
|
-
);
|
|
294
|
-
expect(status).toBe(503);
|
|
295
|
-
await app.stop();
|
|
296
|
-
});
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
import { BareServer } from './server';
|
|
4
|
-
|
|
5
|
-
const TEST_PORT = 8888;
|
|
6
|
-
const app = new BareServer({ serverPort: TEST_PORT });
|
|
7
|
-
|
|
8
|
-
jest.spyOn(console, 'log');
|
|
9
|
-
|
|
10
|
-
afterAll(() => {
|
|
11
|
-
if (app.server.listening) app.stop();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('Starts the server', async () => {
|
|
15
|
-
await app.start(() => console.log('started'));
|
|
16
|
-
|
|
17
|
-
expect(console.log).toHaveBeenCalledWith('started');
|
|
18
|
-
expect(app.server.listening).toBeTruthy();
|
|
19
|
-
await app.stop();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('Shut downs the server', async () => {
|
|
23
|
-
await app.start();
|
|
24
|
-
await app.stop(() => console.log('stopped'));
|
|
25
|
-
|
|
26
|
-
expect(console.log).toHaveBeenCalledWith('stopped');
|
|
27
|
-
expect(app.server.listening).toBeFalsy();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// middlewares;
|
|
31
|
-
test('Registers a middleware through `use`', async () => {
|
|
32
|
-
app.use(() => {});
|
|
33
|
-
|
|
34
|
-
expect(app.getMiddlewares()).toHaveLength(1);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('Registers a middleware through middlewares settings array', async () => {
|
|
38
|
-
const testApp = new BareServer({ middlewares: [() => {}] });
|
|
39
|
-
|
|
40
|
-
expect(testApp.getMiddlewares()).toHaveLength(1);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('Uses middleware', async () => {
|
|
44
|
-
const testApp = new BareServer();
|
|
45
|
-
|
|
46
|
-
testApp.use((flow) => {
|
|
47
|
-
flow.sendStatus(200);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
await testApp.start();
|
|
51
|
-
await expect(axios.get(`http://localhost:3000`)).resolves.toMatchObject({
|
|
52
|
-
status: 200,
|
|
53
|
-
});
|
|
54
|
-
await testApp.stop();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('Uses promise middleware', async () => {
|
|
58
|
-
const testApp = new BareServer();
|
|
59
|
-
|
|
60
|
-
testApp.use(async (flow) => {
|
|
61
|
-
flow.sendStatus(200);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
await testApp.start();
|
|
65
|
-
await expect(axios.get(`http://localhost:3000`)).resolves.toMatchObject({
|
|
66
|
-
status: 200,
|
|
67
|
-
});
|
|
68
|
-
await testApp.stop();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('Fails inside middleware and calls to integrated error handler', async () => {
|
|
72
|
-
const err = new Error('error');
|
|
73
|
-
|
|
74
|
-
app.use(() => {
|
|
75
|
-
throw err;
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
await app.start();
|
|
79
|
-
await expect(() => axios.get(`http://localhost:${TEST_PORT}`)).rejects.toThrow();
|
|
80
|
-
await app.stop();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('Fails inside middleware and calls to custom error handler', async () => {
|
|
84
|
-
const spyEh = jest.fn().mockImplementation((_, flow) => flow.sendStatus(400));
|
|
85
|
-
|
|
86
|
-
app.setCustomErrorHandler(spyEh);
|
|
87
|
-
|
|
88
|
-
await app.start();
|
|
89
|
-
await expect(() => axios.get(`http://localhost:${TEST_PORT}`)).rejects.toThrow();
|
|
90
|
-
await app.stop();
|
|
91
|
-
|
|
92
|
-
expect(spyEh).toHaveBeenCalled();
|
|
93
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
import { BareServer } from './server';
|
|
4
|
-
|
|
5
|
-
const TEST_PORT = 8888;
|
|
6
|
-
const app = new BareServer({ serverPort: TEST_PORT });
|
|
7
|
-
|
|
8
|
-
afterAll(() => {
|
|
9
|
-
if (app.server.listening) app.stop();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
beforeAll(() => {
|
|
13
|
-
app.start();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
// routes
|
|
17
|
-
test('Registers a route with a handler', () => {
|
|
18
|
-
app.route.get({
|
|
19
|
-
route: '/route',
|
|
20
|
-
handler: () => {},
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
expect(app.getRoutes().includes('GET /route')).toBeTruthy();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('Registers a route with options', () => {
|
|
27
|
-
app.route.post({
|
|
28
|
-
route: '/route_settings',
|
|
29
|
-
handler: () => {},
|
|
30
|
-
options: { disableCache: true, timeout: 2000 },
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
expect(app.getRoutes().includes('POST /route_settings')).toBeTruthy();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('Fails if theres an error throw inside route handler', async () => {
|
|
37
|
-
app.route.get({
|
|
38
|
-
route: '/test',
|
|
39
|
-
handler: () => {
|
|
40
|
-
throw new Error();
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
await expect(() => axios.get(`http://localhost:${TEST_PORT}/test`)).rejects.toThrow();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('Returns from the route with `return` keyword', async () => {
|
|
48
|
-
app.route.get({
|
|
49
|
-
route: '/test2',
|
|
50
|
-
handler: () => {
|
|
51
|
-
return 'ALL_OK';
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const response = await axios.get(`http://localhost:${TEST_PORT}/test2`);
|
|
56
|
-
expect(response.data).toBe('ALL_OK');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test("Server doesn't start if timeout is not correct", async () => {
|
|
60
|
-
const app = new BareServer();
|
|
61
|
-
|
|
62
|
-
expect(() =>
|
|
63
|
-
app.route.post({
|
|
64
|
-
route: '/test',
|
|
65
|
-
options: { timeout: 'some timeout' as any },
|
|
66
|
-
handler: async () => {
|
|
67
|
-
return 'ok';
|
|
68
|
-
},
|
|
69
|
-
}),
|
|
70
|
-
).toThrow('Only numeric values are valid per-route timeout, submitted');
|
|
71
|
-
});
|