@furystack/rest-service 6.2.0 → 6.2.1
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/dist/static-server-manager.js +1 -1
- package/dist/static-server-manager.js.map +1 -1
- package/dist/static-server-manager.spec.js +60 -18
- package/dist/static-server-manager.spec.js.map +1 -1
- package/package.json +1 -1
- package/src/static-server-manager.spec.ts +67 -19
- package/src/static-server-manager.ts +3 -1
- package/types/static-server-manager.d.ts.map +1 -1
|
@@ -50,7 +50,7 @@ let StaticServerManager = class StaticServerManager {
|
|
|
50
50
|
'Content-Type': (0, mime_types_1.getMimeForFile)(fullPath),
|
|
51
51
|
};
|
|
52
52
|
res.writeHead(200, head);
|
|
53
|
-
(0, fs_1.createReadStream)(fullPath, { autoClose: true }).pipe(res);
|
|
53
|
+
await new Promise((resolve, reject) => (0, fs_1.createReadStream)(fullPath, { autoClose: true }).once('finish', resolve).once('error', reject).pipe(res));
|
|
54
54
|
}
|
|
55
55
|
async addStaticSite(options) {
|
|
56
56
|
const server = await this.serverManager.getOrCreate({ hostName: options.hostName, port: options.port });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static-server-manager.js","sourceRoot":"","sources":["../src/static-server-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAwD;AACxD,2BAAqC;AACrC,0CAAkC;AAElC,6CAA6C;AAC7C,+BAA2C;AAC3C,qDAAgD;AAYzC,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAAzB;
|
|
1
|
+
{"version":3,"file":"static-server-manager.js","sourceRoot":"","sources":["../src/static-server-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAwD;AACxD,2BAAqC;AACrC,0CAAkC;AAElC,6CAA6C;AAC7C,+BAA2C;AAC3C,qDAAgD;AAYzC,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAAzB;QA2BE,eAAU,GACf,CAAC,OAAe,EAAE,EAAE,CACp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AAQ,EAAE,WAAW,EAAE,CAAC;GACzB,mBAAmB,CAwE/B;AAxEY,kDAAmB"}
|
|
@@ -28,18 +28,34 @@ const utils_1 = require("@furystack/utils");
|
|
|
28
28
|
const got_1 = __importStar(require("got"));
|
|
29
29
|
const server_manager_1 = require("./server-manager");
|
|
30
30
|
const static_server_manager_1 = require("./static-server-manager");
|
|
31
|
+
/**
|
|
32
|
+
* Generator for an incremental port number
|
|
33
|
+
*
|
|
34
|
+
* @param initialPort The initial port number
|
|
35
|
+
* @yields a port for testing
|
|
36
|
+
* @returns The Port number
|
|
37
|
+
*/
|
|
38
|
+
function* getPort(initialPort = 1234) {
|
|
39
|
+
let port = initialPort;
|
|
40
|
+
while (true) {
|
|
41
|
+
yield port++;
|
|
42
|
+
}
|
|
43
|
+
return port;
|
|
44
|
+
}
|
|
31
45
|
describe('StaticServerManager', () => {
|
|
46
|
+
const portGenerator = getPort();
|
|
32
47
|
describe('Top level routing', () => {
|
|
33
48
|
it('Should return a 404 without fallback', async () => {
|
|
34
49
|
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
35
50
|
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
51
|
+
const port = portGenerator.next().value;
|
|
36
52
|
await staticServerManager.addStaticSite({
|
|
37
53
|
baseUrl: '/',
|
|
38
54
|
path: '.',
|
|
39
|
-
port
|
|
55
|
+
port,
|
|
40
56
|
});
|
|
41
57
|
try {
|
|
42
|
-
await got_1.default.get(
|
|
58
|
+
await got_1.default.get(`http://localhost:${port}/not-found.html`);
|
|
43
59
|
}
|
|
44
60
|
catch (error) {
|
|
45
61
|
expect(error).toBeInstanceOf(got_1.RequestError);
|
|
@@ -53,16 +69,35 @@ describe('StaticServerManager', () => {
|
|
|
53
69
|
it('Should return a fallback', async () => {
|
|
54
70
|
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
55
71
|
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
72
|
+
const port = portGenerator.next().value;
|
|
73
|
+
await staticServerManager.addStaticSite({
|
|
74
|
+
baseUrl: '/',
|
|
75
|
+
path: '.',
|
|
76
|
+
fallback: 'package.json',
|
|
77
|
+
port,
|
|
78
|
+
headers: {
|
|
79
|
+
'custom-header': 'custom-value',
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
const result = await got_1.default.get(`http://localhost:${port}/not-found.html`);
|
|
83
|
+
expect(result.headers['content-type']).toBe('application/json');
|
|
84
|
+
expect(result.headers['custom-header']).toBe('custom-value');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it('Should return a fallback for root files', async () => {
|
|
88
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
89
|
+
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
90
|
+
const port = portGenerator.next().value;
|
|
56
91
|
await staticServerManager.addStaticSite({
|
|
57
92
|
baseUrl: '/',
|
|
58
93
|
path: '.',
|
|
59
94
|
fallback: 'package.json',
|
|
60
|
-
port
|
|
95
|
+
port,
|
|
61
96
|
headers: {
|
|
62
97
|
'custom-header': 'custom-value',
|
|
63
98
|
},
|
|
64
99
|
});
|
|
65
|
-
const result = await got_1.default.get(
|
|
100
|
+
const result = await got_1.default.get(`http://localhost:${port}`);
|
|
66
101
|
expect(result.headers['content-type']).toBe('application/json');
|
|
67
102
|
expect(result.headers['custom-header']).toBe('custom-value');
|
|
68
103
|
});
|
|
@@ -70,15 +105,16 @@ describe('StaticServerManager', () => {
|
|
|
70
105
|
it('Should return a defined file from a root directory', async () => {
|
|
71
106
|
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
72
107
|
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
108
|
+
const port = portGenerator.next().value;
|
|
73
109
|
await staticServerManager.addStaticSite({
|
|
74
110
|
baseUrl: '/',
|
|
75
111
|
path: '.',
|
|
76
|
-
port
|
|
112
|
+
port,
|
|
77
113
|
headers: {
|
|
78
114
|
'custom-header': 'custom-value',
|
|
79
115
|
},
|
|
80
116
|
});
|
|
81
|
-
const result = await got_1.default.get(
|
|
117
|
+
const result = await got_1.default.get(`http://localhost:${port}/README.md`);
|
|
82
118
|
expect(result.headers['content-type']).toBe('text/markdown');
|
|
83
119
|
expect(result.headers['custom-header']).toBe('custom-value');
|
|
84
120
|
});
|
|
@@ -86,12 +122,13 @@ describe('StaticServerManager', () => {
|
|
|
86
122
|
it('Should return a defined file from a subdirectory', async () => {
|
|
87
123
|
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
88
124
|
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
125
|
+
const port = portGenerator.next().value;
|
|
89
126
|
await staticServerManager.addStaticSite({
|
|
90
127
|
baseUrl: '/',
|
|
91
128
|
path: '.',
|
|
92
|
-
port
|
|
129
|
+
port,
|
|
93
130
|
});
|
|
94
|
-
const result = await got_1.default.get(
|
|
131
|
+
const result = await got_1.default.get(`http://localhost:${port}/packages/utils/README.md`);
|
|
95
132
|
expect(result.headers['content-type']).toBe('text/markdown');
|
|
96
133
|
});
|
|
97
134
|
});
|
|
@@ -100,14 +137,15 @@ describe('StaticServerManager', () => {
|
|
|
100
137
|
it('Should not handle a request when the path is not matching', async () => {
|
|
101
138
|
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
102
139
|
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
140
|
+
const port = portGenerator.next().value;
|
|
103
141
|
await staticServerManager.addStaticSite({
|
|
104
142
|
baseUrl: '/bundle',
|
|
105
143
|
path: '.',
|
|
106
|
-
port
|
|
144
|
+
port,
|
|
107
145
|
});
|
|
108
146
|
const server = [...injector.getInstance(server_manager_1.ServerManager).servers.values()][0];
|
|
109
147
|
server.apis[0].onRequest = jest.fn();
|
|
110
|
-
got_1.default.get(
|
|
148
|
+
got_1.default.get(`http://localhost:${port}/bundleToAnotherFolder/not-found.html`);
|
|
111
149
|
await (0, utils_1.sleepAsync)(100);
|
|
112
150
|
expect(server.apis[0].onRequest).not.toHaveBeenCalled();
|
|
113
151
|
});
|
|
@@ -115,13 +153,14 @@ describe('StaticServerManager', () => {
|
|
|
115
153
|
it('Should return a 404 without fallback', async () => {
|
|
116
154
|
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
117
155
|
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
156
|
+
const port = portGenerator.next().value;
|
|
118
157
|
await staticServerManager.addStaticSite({
|
|
119
158
|
baseUrl: '/bundle',
|
|
120
159
|
path: '.',
|
|
121
|
-
port
|
|
160
|
+
port,
|
|
122
161
|
});
|
|
123
162
|
try {
|
|
124
|
-
await got_1.default.get(
|
|
163
|
+
await got_1.default.get(`http://localhost:${port}/bundle/not-found.html`);
|
|
125
164
|
}
|
|
126
165
|
catch (error) {
|
|
127
166
|
expect(error).toBeInstanceOf(got_1.RequestError);
|
|
@@ -135,37 +174,40 @@ describe('StaticServerManager', () => {
|
|
|
135
174
|
it('Should return a fallback', async () => {
|
|
136
175
|
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
137
176
|
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
177
|
+
const port = portGenerator.next().value;
|
|
138
178
|
await staticServerManager.addStaticSite({
|
|
139
179
|
baseUrl: '/bundle',
|
|
140
180
|
path: '.',
|
|
141
181
|
fallback: 'package.json',
|
|
142
|
-
port
|
|
182
|
+
port,
|
|
143
183
|
});
|
|
144
|
-
const result = await got_1.default.get(
|
|
184
|
+
const result = await got_1.default.get(`http://localhost:${port}/bundle/not-found.html`);
|
|
145
185
|
expect(result.headers['content-type']).toBe('application/json');
|
|
146
186
|
});
|
|
147
187
|
});
|
|
148
188
|
it('Should return a defined file from a root directory', async () => {
|
|
149
189
|
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
150
190
|
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
191
|
+
const port = portGenerator.next().value;
|
|
151
192
|
await staticServerManager.addStaticSite({
|
|
152
193
|
baseUrl: '/',
|
|
153
194
|
path: '.',
|
|
154
|
-
port
|
|
195
|
+
port,
|
|
155
196
|
});
|
|
156
|
-
const result = await got_1.default.get(
|
|
197
|
+
const result = await got_1.default.get(`http://localhost:${port}/README.md`);
|
|
157
198
|
expect(result.headers['content-type']).toBe('text/markdown');
|
|
158
199
|
});
|
|
159
200
|
});
|
|
160
201
|
it('Should return a defined file from a subdirectory', async () => {
|
|
161
202
|
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
162
203
|
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
204
|
+
const port = portGenerator.next().value;
|
|
163
205
|
await staticServerManager.addStaticSite({
|
|
164
206
|
baseUrl: '/',
|
|
165
207
|
path: '.',
|
|
166
|
-
port
|
|
208
|
+
port,
|
|
167
209
|
});
|
|
168
|
-
const result = await got_1.default.get(
|
|
210
|
+
const result = await got_1.default.get(`http://localhost:${port}/packages/utils/README.md`);
|
|
169
211
|
expect(result.headers['content-type']).toBe('text/markdown');
|
|
170
212
|
});
|
|
171
213
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static-server-manager.spec.js","sourceRoot":"","sources":["../src/static-server-manager.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAA4C;AAC5C,4CAAyD;AACzD,2CAAuC;AACvC,qDAAgD;AAChD,mEAA6D;AAE7D,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;QACjC,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;YACpD,MAAM,IAAA,kBAAU,EAAC,IAAI,iBAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;gBAClD,MA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,CAAC,CAAA;YACxF,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC/B,CAAC,CAAC,CACH,CAAA;QAED,EAAE,CAAC,kEAAkE,EAAE,GAAG,EAAE;YAC1E,MAAM,mBAAmB,GAAG,IAAI,2CAAmB,EAAE,CAAA;YACrD,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACnG,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,mBAAmB,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAC1G,KAAK,CACN,CAAA;YACD,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YAC1G,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,qBAAqB,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAC5G,KAAK,CACN,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -4,20 +4,38 @@ import got, { RequestError } from 'got'
|
|
|
4
4
|
import { ServerManager } from './server-manager'
|
|
5
5
|
import { StaticServerManager } from './static-server-manager'
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Generator for an incremental port number
|
|
9
|
+
*
|
|
10
|
+
* @param initialPort The initial port number
|
|
11
|
+
* @yields a port for testing
|
|
12
|
+
* @returns The Port number
|
|
13
|
+
*/
|
|
14
|
+
function* getPort(initialPort = 1234) {
|
|
15
|
+
let port = initialPort
|
|
16
|
+
|
|
17
|
+
while (true) {
|
|
18
|
+
yield port++
|
|
19
|
+
}
|
|
20
|
+
return port
|
|
21
|
+
}
|
|
22
|
+
|
|
7
23
|
describe('StaticServerManager', () => {
|
|
24
|
+
const portGenerator = getPort()
|
|
25
|
+
|
|
8
26
|
describe('Top level routing', () => {
|
|
9
27
|
it('Should return a 404 without fallback', async () => {
|
|
10
28
|
await usingAsync(new Injector(), async (injector) => {
|
|
11
29
|
const staticServerManager = injector.getInstance(StaticServerManager)
|
|
12
|
-
|
|
30
|
+
const port = portGenerator.next().value
|
|
13
31
|
await staticServerManager.addStaticSite({
|
|
14
32
|
baseUrl: '/',
|
|
15
33
|
path: '.',
|
|
16
|
-
port
|
|
34
|
+
port,
|
|
17
35
|
})
|
|
18
36
|
|
|
19
37
|
try {
|
|
20
|
-
await got.get(
|
|
38
|
+
await got.get(`http://localhost:${port}/not-found.html`)
|
|
21
39
|
} catch (error) {
|
|
22
40
|
expect(error).toBeInstanceOf(RequestError)
|
|
23
41
|
const requestError: RequestError = error as RequestError
|
|
@@ -32,18 +50,41 @@ describe('StaticServerManager', () => {
|
|
|
32
50
|
it('Should return a fallback', async () => {
|
|
33
51
|
await usingAsync(new Injector(), async (injector) => {
|
|
34
52
|
const staticServerManager = injector.getInstance(StaticServerManager)
|
|
53
|
+
const port = portGenerator.next().value
|
|
54
|
+
|
|
55
|
+
await staticServerManager.addStaticSite({
|
|
56
|
+
baseUrl: '/',
|
|
57
|
+
path: '.',
|
|
58
|
+
fallback: 'package.json',
|
|
59
|
+
port,
|
|
60
|
+
headers: {
|
|
61
|
+
'custom-header': 'custom-value',
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const result = await got.get(`http://localhost:${port}/not-found.html`)
|
|
66
|
+
|
|
67
|
+
expect(result.headers['content-type']).toBe('application/json')
|
|
68
|
+
expect(result.headers['custom-header']).toBe('custom-value')
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('Should return a fallback for root files', async () => {
|
|
73
|
+
await usingAsync(new Injector(), async (injector) => {
|
|
74
|
+
const staticServerManager = injector.getInstance(StaticServerManager)
|
|
75
|
+
const port = portGenerator.next().value
|
|
35
76
|
|
|
36
77
|
await staticServerManager.addStaticSite({
|
|
37
78
|
baseUrl: '/',
|
|
38
79
|
path: '.',
|
|
39
80
|
fallback: 'package.json',
|
|
40
|
-
port
|
|
81
|
+
port,
|
|
41
82
|
headers: {
|
|
42
83
|
'custom-header': 'custom-value',
|
|
43
84
|
},
|
|
44
85
|
})
|
|
45
86
|
|
|
46
|
-
const result = await got.get(
|
|
87
|
+
const result = await got.get(`http://localhost:${port}`)
|
|
47
88
|
|
|
48
89
|
expect(result.headers['content-type']).toBe('application/json')
|
|
49
90
|
expect(result.headers['custom-header']).toBe('custom-value')
|
|
@@ -53,17 +94,18 @@ describe('StaticServerManager', () => {
|
|
|
53
94
|
it('Should return a defined file from a root directory', async () => {
|
|
54
95
|
await usingAsync(new Injector(), async (injector) => {
|
|
55
96
|
const staticServerManager = injector.getInstance(StaticServerManager)
|
|
97
|
+
const port = portGenerator.next().value
|
|
56
98
|
|
|
57
99
|
await staticServerManager.addStaticSite({
|
|
58
100
|
baseUrl: '/',
|
|
59
101
|
path: '.',
|
|
60
|
-
port
|
|
102
|
+
port,
|
|
61
103
|
headers: {
|
|
62
104
|
'custom-header': 'custom-value',
|
|
63
105
|
},
|
|
64
106
|
})
|
|
65
107
|
|
|
66
|
-
const result = await got.get(
|
|
108
|
+
const result = await got.get(`http://localhost:${port}/README.md`)
|
|
67
109
|
|
|
68
110
|
expect(result.headers['content-type']).toBe('text/markdown')
|
|
69
111
|
expect(result.headers['custom-header']).toBe('custom-value')
|
|
@@ -73,14 +115,15 @@ describe('StaticServerManager', () => {
|
|
|
73
115
|
it('Should return a defined file from a subdirectory', async () => {
|
|
74
116
|
await usingAsync(new Injector(), async (injector) => {
|
|
75
117
|
const staticServerManager = injector.getInstance(StaticServerManager)
|
|
118
|
+
const port = portGenerator.next().value
|
|
76
119
|
|
|
77
120
|
await staticServerManager.addStaticSite({
|
|
78
121
|
baseUrl: '/',
|
|
79
122
|
path: '.',
|
|
80
|
-
port
|
|
123
|
+
port,
|
|
81
124
|
})
|
|
82
125
|
|
|
83
|
-
const result = await got.get(
|
|
126
|
+
const result = await got.get(`http://localhost:${port}/packages/utils/README.md`)
|
|
84
127
|
|
|
85
128
|
expect(result.headers['content-type']).toBe('text/markdown')
|
|
86
129
|
})
|
|
@@ -91,18 +134,19 @@ describe('StaticServerManager', () => {
|
|
|
91
134
|
it('Should not handle a request when the path is not matching', async () => {
|
|
92
135
|
await usingAsync(new Injector(), async (injector) => {
|
|
93
136
|
const staticServerManager = injector.getInstance(StaticServerManager)
|
|
137
|
+
const port = portGenerator.next().value
|
|
94
138
|
|
|
95
139
|
await staticServerManager.addStaticSite({
|
|
96
140
|
baseUrl: '/bundle',
|
|
97
141
|
path: '.',
|
|
98
|
-
port
|
|
142
|
+
port,
|
|
99
143
|
})
|
|
100
144
|
|
|
101
145
|
const server = [...injector.getInstance(ServerManager).servers.values()][0]
|
|
102
146
|
|
|
103
147
|
server.apis[0].onRequest = jest.fn()
|
|
104
148
|
|
|
105
|
-
got.get(
|
|
149
|
+
got.get(`http://localhost:${port}/bundleToAnotherFolder/not-found.html`)
|
|
106
150
|
|
|
107
151
|
await sleepAsync(100)
|
|
108
152
|
|
|
@@ -113,15 +157,16 @@ describe('StaticServerManager', () => {
|
|
|
113
157
|
it('Should return a 404 without fallback', async () => {
|
|
114
158
|
await usingAsync(new Injector(), async (injector) => {
|
|
115
159
|
const staticServerManager = injector.getInstance(StaticServerManager)
|
|
160
|
+
const port = portGenerator.next().value
|
|
116
161
|
|
|
117
162
|
await staticServerManager.addStaticSite({
|
|
118
163
|
baseUrl: '/bundle',
|
|
119
164
|
path: '.',
|
|
120
|
-
port
|
|
165
|
+
port,
|
|
121
166
|
})
|
|
122
167
|
|
|
123
168
|
try {
|
|
124
|
-
await got.get(
|
|
169
|
+
await got.get(`http://localhost:${port}/bundle/not-found.html`)
|
|
125
170
|
} catch (error) {
|
|
126
171
|
expect(error).toBeInstanceOf(RequestError)
|
|
127
172
|
const requestError: RequestError = error as RequestError
|
|
@@ -136,15 +181,16 @@ describe('StaticServerManager', () => {
|
|
|
136
181
|
it('Should return a fallback', async () => {
|
|
137
182
|
await usingAsync(new Injector(), async (injector) => {
|
|
138
183
|
const staticServerManager = injector.getInstance(StaticServerManager)
|
|
184
|
+
const port = portGenerator.next().value
|
|
139
185
|
|
|
140
186
|
await staticServerManager.addStaticSite({
|
|
141
187
|
baseUrl: '/bundle',
|
|
142
188
|
path: '.',
|
|
143
189
|
fallback: 'package.json',
|
|
144
|
-
port
|
|
190
|
+
port,
|
|
145
191
|
})
|
|
146
192
|
|
|
147
|
-
const result = await got.get(
|
|
193
|
+
const result = await got.get(`http://localhost:${port}/bundle/not-found.html`)
|
|
148
194
|
|
|
149
195
|
expect(result.headers['content-type']).toBe('application/json')
|
|
150
196
|
})
|
|
@@ -153,14 +199,15 @@ describe('StaticServerManager', () => {
|
|
|
153
199
|
it('Should return a defined file from a root directory', async () => {
|
|
154
200
|
await usingAsync(new Injector(), async (injector) => {
|
|
155
201
|
const staticServerManager = injector.getInstance(StaticServerManager)
|
|
202
|
+
const port = portGenerator.next().value
|
|
156
203
|
|
|
157
204
|
await staticServerManager.addStaticSite({
|
|
158
205
|
baseUrl: '/',
|
|
159
206
|
path: '.',
|
|
160
|
-
port
|
|
207
|
+
port,
|
|
161
208
|
})
|
|
162
209
|
|
|
163
|
-
const result = await got.get(
|
|
210
|
+
const result = await got.get(`http://localhost:${port}/README.md`)
|
|
164
211
|
|
|
165
212
|
expect(result.headers['content-type']).toBe('text/markdown')
|
|
166
213
|
})
|
|
@@ -169,14 +216,15 @@ describe('StaticServerManager', () => {
|
|
|
169
216
|
it('Should return a defined file from a subdirectory', async () => {
|
|
170
217
|
await usingAsync(new Injector(), async (injector) => {
|
|
171
218
|
const staticServerManager = injector.getInstance(StaticServerManager)
|
|
219
|
+
const port = portGenerator.next().value
|
|
172
220
|
|
|
173
221
|
await staticServerManager.addStaticSite({
|
|
174
222
|
baseUrl: '/',
|
|
175
223
|
path: '.',
|
|
176
|
-
port
|
|
224
|
+
port,
|
|
177
225
|
})
|
|
178
226
|
|
|
179
|
-
const result = await got.get(
|
|
227
|
+
const result = await got.get(`http://localhost:${port}/packages/utils/README.md`)
|
|
180
228
|
|
|
181
229
|
expect(result.headers['content-type']).toBe('text/markdown')
|
|
182
230
|
})
|
|
@@ -38,7 +38,9 @@ export class StaticServerManager {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
res.writeHead(200, head)
|
|
41
|
-
|
|
41
|
+
await new Promise<void>((resolve, reject) =>
|
|
42
|
+
createReadStream(fullPath, { autoClose: true }).once('finish', resolve).once('error', reject).pipe(res),
|
|
43
|
+
)
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
public shouldExec =
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static-server-manager.d.ts","sourceRoot":"","sources":["../src/static-server-manager.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAkB,MAAM,MAAM,CAAA;AAKhF,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,mBAAmB,CAAA;CAC9B;AAED,qBACa,mBAAmB;IAE9B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;YAEhC,QAAQ;
|
|
1
|
+
{"version":3,"file":"static-server-manager.d.ts","sourceRoot":"","sources":["../src/static-server-manager.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAkB,MAAM,MAAM,CAAA;AAKhF,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,mBAAmB,CAAA;CAC9B;AAED,qBACa,mBAAmB;IAE9B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;YAEhC,QAAQ;IAuBf,UAAU,YACL,MAAM;aACC,KAAK,eAAe,EAAE,KAAK,GAAG,QAAQ,CAAC;kBAK7C;IAEb,OAAO,CAAC,SAAS,CA0BhB;IAEY,aAAa,CAAC,OAAO,EAAE,mBAAmB;CAQxD"}
|