miqro 6.2.4 → 6.2.5
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/build/esm/src/inflate/setup-http.js +327 -324
- package/build/lib.cjs +305 -302
- package/package.json +1 -1
- package/src/inflate/setup-http.ts +341 -338
|
@@ -165,338 +165,279 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
165
165
|
}> {
|
|
166
166
|
const router = new Router();
|
|
167
167
|
router.use(assertGlobalTampered);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName, module);
|
|
186
|
-
|
|
187
|
-
routeFileMap[file.filePath] = {
|
|
188
|
-
routes,
|
|
189
|
-
service,
|
|
190
|
-
filePath: file.filePath,
|
|
191
|
-
previewMethod: "api"
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
const inflatedCode = inflateDir ? await inflateJSX(file.filePath, {
|
|
195
|
-
embemedJSX: false,
|
|
196
|
-
minify: false,
|
|
197
|
-
useExport: true,
|
|
198
|
-
platform: "node",
|
|
199
|
-
logger
|
|
200
|
-
}) : "";
|
|
201
|
-
|
|
202
|
-
for (const r of routes) {
|
|
203
|
-
|
|
204
|
-
/*if (inflateDir && r.inflatePath) {
|
|
205
|
-
const rPath = r.inflatePath;
|
|
206
|
-
const inflatePath = join(inflateDir, service, "http", rPath + ".api.js");
|
|
207
|
-
mkdirSync(dirname(inflatePath), {
|
|
208
|
-
recursive: true
|
|
209
|
-
});
|
|
210
|
-
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
211
|
-
writeFileSync(inflatePath, inflatedCode);
|
|
212
|
-
}*/
|
|
213
|
-
|
|
214
|
-
if (inflateDir && r.defaultInflatePath && inflateSea) {
|
|
215
|
-
const rPath = r.defaultInflatePath;
|
|
216
|
-
const inflatePath = join(inflateDir, service, "http", rPath + ".api.cjs");
|
|
217
|
-
mkdirSync(dirname(inflatePath), {
|
|
218
|
-
recursive: true
|
|
219
|
-
});
|
|
220
|
-
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
221
|
-
writeFileSync(inflatePath, inflatedCode);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
router.use(assertGlobalTampered);
|
|
226
|
-
router.use(module.handler, r.path, r.method as any, r.options);
|
|
227
|
-
}
|
|
228
|
-
return resolve();
|
|
229
|
-
}
|
|
230
|
-
case ".json": {
|
|
231
|
-
const module = await importJSONModule(file.filePath, logger);
|
|
232
|
-
const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName + ".json", module.apiOptions as Partial<APIRoute>);
|
|
233
|
-
|
|
234
|
-
routeFileMap[file.filePath] = {
|
|
235
|
-
routes,
|
|
236
|
-
service,
|
|
237
|
-
filePath: file.filePath,
|
|
238
|
-
previewMethod: "html"
|
|
239
|
-
};
|
|
168
|
+
for (const file of scanFiles(dir)) {
|
|
169
|
+
await new Promise<void>(async (resolve) => {
|
|
170
|
+
try {
|
|
171
|
+
switch (file.ext) {
|
|
172
|
+
case ".jsx":
|
|
173
|
+
case ".cjs":
|
|
174
|
+
case ".js":
|
|
175
|
+
case ".ts":
|
|
176
|
+
case ".tsx": {
|
|
177
|
+
switch (file.subExt) {
|
|
178
|
+
case ".test":
|
|
179
|
+
return resolve();
|
|
180
|
+
case ".ignore":
|
|
181
|
+
logger.warn("ignoring [%s]", file.filePath);
|
|
182
|
+
return resolve();
|
|
183
|
+
case ".api": {
|
|
240
184
|
|
|
241
|
-
|
|
185
|
+
const module = await importAPIRoute(file.filePath, logger);
|
|
242
186
|
|
|
243
|
-
const
|
|
187
|
+
const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName, module);
|
|
244
188
|
|
|
189
|
+
routeFileMap[file.filePath] = {
|
|
190
|
+
routes,
|
|
191
|
+
service,
|
|
192
|
+
filePath: file.filePath,
|
|
193
|
+
previewMethod: "api"
|
|
194
|
+
};
|
|
245
195
|
|
|
196
|
+
const inflatedCode = inflateDir ? await inflateJSX(file.filePath, {
|
|
197
|
+
embemedJSX: false,
|
|
198
|
+
minify: false,
|
|
199
|
+
useExport: true,
|
|
200
|
+
platform: "node",
|
|
201
|
+
logger
|
|
202
|
+
}) : "";
|
|
246
203
|
|
|
247
|
-
|
|
204
|
+
for (const r of routes) {
|
|
248
205
|
|
|
249
|
-
if (r.inflatePath) {
|
|
250
|
-
//if (r.method === "GET" || r.method === "get") {
|
|
206
|
+
/*if (inflateDir && r.inflatePath) {
|
|
251
207
|
const rPath = r.inflatePath;
|
|
252
|
-
const inflatePath = join(inflateDir, service, "
|
|
208
|
+
const inflatePath = join(inflateDir, service, "http", rPath + ".api.js");
|
|
253
209
|
mkdirSync(dirname(inflatePath), {
|
|
254
210
|
recursive: true
|
|
255
211
|
});
|
|
256
|
-
if (existsSync(inflatePath) && statSync(inflatePath).isDirectory()) {
|
|
257
|
-
logger.trace("ignoring writing over directory [%s] for file [%s]", relative(cwd(), inflatePath), file.filePath);
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
const JSON_STATIC = await getJSON({ server } as ServerRequest, null, newURL(r.path), module.apiOptions?.basePath, module.default);
|
|
261
|
-
//const JSON = await getJSON({ server } as ServerRequest, null, newURL(r.path), module.apiOptions?.basePath, module.default);
|
|
262
212
|
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
263
|
-
writeFileSync(inflatePath,
|
|
264
|
-
|
|
213
|
+
writeFileSync(inflatePath, inflatedCode);
|
|
214
|
+
}*/
|
|
265
215
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
inflatePath: inflateDir ? join(inflateDir, service, "static", r.inflatePath) : undefined
|
|
275
|
-
}
|
|
276
|
-
}
|
|
216
|
+
if (inflateDir && r.defaultInflatePath && inflateSea) {
|
|
217
|
+
const rPath = r.defaultInflatePath;
|
|
218
|
+
const inflatePath = join(inflateDir, service, "http", rPath + ".api.cjs");
|
|
219
|
+
mkdirSync(dirname(inflatePath), {
|
|
220
|
+
recursive: true
|
|
221
|
+
});
|
|
222
|
+
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
223
|
+
writeFileSync(inflatePath, inflatedCode);
|
|
277
224
|
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
router.use(assertGlobalTampered);
|
|
281
|
-
router.use(async function (req: Request, res: Response) {
|
|
282
225
|
|
|
283
|
-
const JSON = await getJSON(req, res, newURL(req.path), module.apiOptions?.basePath, module.default);
|
|
284
226
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
},
|
|
290
|
-
body: JSON
|
|
291
|
-
});
|
|
292
|
-
}, r.path, r.method as any, r.options)
|
|
227
|
+
router.use(assertGlobalTampered);
|
|
228
|
+
router.use(module.handler, r.path, r.method as any, r.options);
|
|
229
|
+
}
|
|
230
|
+
return resolve();
|
|
293
231
|
}
|
|
232
|
+
case ".json": {
|
|
233
|
+
const module = await importJSONModule(file.filePath, logger);
|
|
234
|
+
const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName + ".json", module.apiOptions as Partial<APIRoute>);
|
|
294
235
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
236
|
+
routeFileMap[file.filePath] = {
|
|
237
|
+
routes,
|
|
238
|
+
service,
|
|
239
|
+
filePath: file.filePath,
|
|
240
|
+
previewMethod: "html"
|
|
241
|
+
};
|
|
300
242
|
|
|
301
|
-
|
|
243
|
+
for (const r of routes) {
|
|
302
244
|
|
|
303
|
-
|
|
304
|
-
routes,
|
|
305
|
-
filePath: file.filePath,
|
|
306
|
-
service,
|
|
307
|
-
previewMethod: "html"
|
|
308
|
-
};
|
|
245
|
+
const contentType = CONTENT_TYPE_MAP[".json"] ? CONTENT_TYPE_MAP[".json"] : DEFAULT_CONTENT_TYPE;
|
|
309
246
|
|
|
310
|
-
for (const r of routes) {
|
|
311
247
|
|
|
312
|
-
const contentType = CONTENT_TYPE_MAP[".html"] ? CONTENT_TYPE_MAP[".html"] : DEFAULT_CONTENT_TYPE;
|
|
313
248
|
|
|
314
|
-
|
|
249
|
+
if (inflateDir) {
|
|
315
250
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
251
|
+
if (r.inflatePath) {
|
|
252
|
+
//if (r.method === "GET" || r.method === "get") {
|
|
253
|
+
const rPath = r.inflatePath;
|
|
254
|
+
const inflatePath = join(inflateDir, service, "static", rPath);
|
|
255
|
+
mkdirSync(dirname(inflatePath), {
|
|
256
|
+
recursive: true
|
|
257
|
+
});
|
|
258
|
+
if (existsSync(inflatePath) && statSync(inflatePath).isDirectory()) {
|
|
259
|
+
logger.trace("ignoring writing over directory [%s] for file [%s]", relative(cwd(), inflatePath), file.filePath);
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
const JSON_STATIC = await getJSON({ server } as ServerRequest, null, newURL(r.path), module.apiOptions?.basePath, module.default);
|
|
263
|
+
//const JSON = await getJSON({ server } as ServerRequest, null, newURL(r.path), module.apiOptions?.basePath, module.default);
|
|
264
|
+
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
265
|
+
writeFileSync(inflatePath, JSON_STATIC);
|
|
266
|
+
//}
|
|
267
|
+
|
|
268
|
+
if (staticFileMap && inflateSea) {
|
|
269
|
+
staticFileMap[file.filePath] = {
|
|
270
|
+
contentType,
|
|
271
|
+
filePath: file.filePath,
|
|
272
|
+
method: r.method,
|
|
273
|
+
previewMethod: "html",
|
|
274
|
+
path: r.path,
|
|
275
|
+
body: Buffer.from(JSON_STATIC),
|
|
276
|
+
inflatePath: inflateDir ? join(inflateDir, service, "static", r.inflatePath) : undefined
|
|
277
|
+
}
|
|
278
|
+
}
|
|
326
279
|
}
|
|
327
|
-
|
|
328
|
-
const HTML_STATIC = await getHTML(hotreload, { server } as ServerRequest, null, newURL(r.path), module.apiOptions?.basePath, await toRender);
|
|
280
|
+
}
|
|
329
281
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
//}
|
|
282
|
+
router.use(assertGlobalTampered);
|
|
283
|
+
router.use(async function (req: Request, res: Response) {
|
|
333
284
|
|
|
285
|
+
const JSON = await getJSON(req, res, newURL(req.path), module.apiOptions?.basePath, module.default);
|
|
334
286
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
contentType
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
inflatePath: inflateDir ? join(inflateDir, service, "static", r.inflatePath) : undefined
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
287
|
+
return res.asyncEnd({
|
|
288
|
+
status: 200,
|
|
289
|
+
headers: {
|
|
290
|
+
["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
|
|
291
|
+
},
|
|
292
|
+
body: JSON
|
|
293
|
+
});
|
|
294
|
+
}, r.path, r.method as any, r.options)
|
|
347
295
|
}
|
|
348
296
|
|
|
349
|
-
|
|
350
|
-
router.use(async function (req: Request, res: Response) {
|
|
351
|
-
const toRender = typeof module.default === "function" ? module.default(req, res) : module.default;
|
|
352
|
-
const HTML = await getHTML(hotreload, req, res, newURL(req.path), module.apiOptions?.basePath, await toRender);
|
|
353
|
-
|
|
354
|
-
return res.asyncEnd({
|
|
355
|
-
status: 200,
|
|
356
|
-
headers: {
|
|
357
|
-
["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
|
|
358
|
-
},
|
|
359
|
-
body: HTML
|
|
360
|
-
});
|
|
361
|
-
}, r.path, r.method as any, r.options)
|
|
297
|
+
return resolve();
|
|
362
298
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
// allow fall-through when extension is .js and .ts because is a static route without embemedJSX
|
|
369
|
-
if (file.ext !== ".js" && file.ext !== ".ts") {
|
|
370
|
-
const code = await inflateJSX(file.filePath, {
|
|
371
|
-
embemedJSX: true,
|
|
372
|
-
minify: file.subExt === ".min" ? true : false,
|
|
373
|
-
useExport: false,
|
|
374
|
-
logger
|
|
375
|
-
});
|
|
376
|
-
const contentType = CONTENT_TYPE_MAP[".js"];
|
|
377
|
-
const path = join("/", dirname(relative(dir, file.filePath)), file.name + ".js");
|
|
299
|
+
case ".html": {
|
|
300
|
+
|
|
301
|
+
const module = await importHTMLModule(file.filePath, logger);
|
|
302
|
+
|
|
303
|
+
const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName + ".html", module.apiOptions as Partial<APIRoute>);
|
|
378
304
|
|
|
379
305
|
routeFileMap[file.filePath] = {
|
|
380
|
-
routes
|
|
381
|
-
method: "GET",
|
|
382
|
-
path
|
|
383
|
-
}],
|
|
306
|
+
routes,
|
|
384
307
|
filePath: file.filePath,
|
|
385
308
|
service,
|
|
386
309
|
previewMethod: "html"
|
|
387
310
|
};
|
|
388
311
|
|
|
389
|
-
|
|
390
|
-
const inflatePath = join(inflateDir, service, "static", path);
|
|
391
|
-
mkdirSync(dirname(inflatePath), {
|
|
392
|
-
recursive: true
|
|
393
|
-
});
|
|
394
|
-
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
395
|
-
writeFileSync(inflatePath, code);
|
|
312
|
+
for (const r of routes) {
|
|
396
313
|
|
|
314
|
+
const contentType = CONTENT_TYPE_MAP[".html"] ? CONTENT_TYPE_MAP[".html"] : DEFAULT_CONTENT_TYPE;
|
|
397
315
|
|
|
398
|
-
if (
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
316
|
+
if (inflateDir) {
|
|
317
|
+
|
|
318
|
+
if (r.inflatePath) {
|
|
319
|
+
//if (r.method === "GET" || r.method === "get") {
|
|
320
|
+
const rPath = r.inflatePath;
|
|
321
|
+
const inflatePath = join(inflateDir, service, "static", rPath);
|
|
322
|
+
mkdirSync(dirname(inflatePath), {
|
|
323
|
+
recursive: true
|
|
324
|
+
});
|
|
325
|
+
if (existsSync(inflatePath) && statSync(inflatePath).isDirectory()) {
|
|
326
|
+
logger.trace("ignoring writing over directory [%s] for file [%s]", relative(cwd(), inflatePath), file.filePath);
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
const toRender = typeof module.default === "function" ? module.default({ server } as ServerRequest, null) : module.default;
|
|
330
|
+
const HTML_STATIC = await getHTML(hotreload, { server } as ServerRequest, null, newURL(r.path), module.apiOptions?.basePath, await toRender);
|
|
331
|
+
|
|
332
|
+
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
333
|
+
writeFileSync(inflatePath, HTML_STATIC);
|
|
334
|
+
//}
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
if (staticFileMap && inflateSea) {
|
|
338
|
+
staticFileMap[file.filePath + r.method + r.path] = {
|
|
339
|
+
filePath: file.filePath,
|
|
340
|
+
contentType,
|
|
341
|
+
method: r.method,
|
|
342
|
+
previewMethod: "html",
|
|
343
|
+
path: r.path,
|
|
344
|
+
body: Buffer.from(HTML_STATIC),
|
|
345
|
+
inflatePath: inflateDir ? join(inflateDir, service, "static", r.inflatePath) : undefined
|
|
346
|
+
}
|
|
347
|
+
}
|
|
407
348
|
}
|
|
408
349
|
}
|
|
409
|
-
}
|
|
410
350
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
351
|
+
router.use(assertGlobalTampered);
|
|
352
|
+
router.use(async function (req: Request, res: Response) {
|
|
353
|
+
const toRender = typeof module.default === "function" ? module.default(req, res) : module.default;
|
|
354
|
+
const HTML = await getHTML(hotreload, req, res, newURL(req.path), module.apiOptions?.basePath, await toRender);
|
|
355
|
+
|
|
356
|
+
return res.asyncEnd({
|
|
357
|
+
status: 200,
|
|
358
|
+
headers: {
|
|
359
|
+
["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
|
|
360
|
+
},
|
|
361
|
+
body: HTML
|
|
362
|
+
});
|
|
363
|
+
}, r.path, r.method as any, r.options)
|
|
364
|
+
}
|
|
421
365
|
return resolve();
|
|
422
366
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
path
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if (inflateDir) {
|
|
443
|
-
const inflatePath = join(inflateDir, service, "static", path);
|
|
444
|
-
mkdirSync(dirname(inflatePath), {
|
|
445
|
-
recursive: true
|
|
446
|
-
});
|
|
447
|
-
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
448
|
-
writeFileSync(inflatePath, code);
|
|
449
|
-
if (staticFileMap && inflateSea) {
|
|
450
|
-
staticFileMap[file.filePath] = {
|
|
451
|
-
contentType,
|
|
452
|
-
method: "GET",
|
|
367
|
+
case ".min":
|
|
368
|
+
case ".js":
|
|
369
|
+
default: {
|
|
370
|
+
// allow fall-through when extension is .js and .ts because is a static route without embemedJSX
|
|
371
|
+
if (file.ext !== ".js" && file.ext !== ".ts") {
|
|
372
|
+
const code = await inflateJSX(file.filePath, {
|
|
373
|
+
embemedJSX: true,
|
|
374
|
+
minify: file.subExt === ".min" ? true : false,
|
|
375
|
+
useExport: false,
|
|
376
|
+
logger
|
|
377
|
+
});
|
|
378
|
+
const contentType = CONTENT_TYPE_MAP[".js"];
|
|
379
|
+
const path = join("/", dirname(relative(dir, file.filePath)), file.name + ".js");
|
|
380
|
+
|
|
381
|
+
routeFileMap[file.filePath] = {
|
|
382
|
+
routes: [{
|
|
383
|
+
method: "GET",
|
|
384
|
+
path
|
|
385
|
+
}],
|
|
453
386
|
filePath: file.filePath,
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
387
|
+
service,
|
|
388
|
+
previewMethod: "html"
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
if (inflateDir) {
|
|
392
|
+
const inflatePath = join(inflateDir, service, "static", path);
|
|
393
|
+
mkdirSync(dirname(inflatePath), {
|
|
394
|
+
recursive: true
|
|
395
|
+
});
|
|
396
|
+
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
397
|
+
writeFileSync(inflatePath, code);
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
if (staticFileMap && inflateSea) {
|
|
401
|
+
staticFileMap[file.filePath] = {
|
|
402
|
+
contentType,
|
|
403
|
+
filePath: file.filePath,
|
|
404
|
+
method: "GET",
|
|
405
|
+
previewMethod: "html",
|
|
406
|
+
path,
|
|
407
|
+
body: Buffer.from(code),
|
|
408
|
+
inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
|
|
409
|
+
}
|
|
410
|
+
}
|
|
458
411
|
}
|
|
412
|
+
|
|
413
|
+
router.use(assertGlobalTampered);
|
|
414
|
+
router.get(path, async function (req, res) {
|
|
415
|
+
return res.asyncEnd({
|
|
416
|
+
status: 200,
|
|
417
|
+
headers: {
|
|
418
|
+
["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
|
|
419
|
+
},
|
|
420
|
+
body: code
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
return resolve();
|
|
459
424
|
}
|
|
460
425
|
}
|
|
461
|
-
|
|
462
|
-
router.use(assertGlobalTampered);
|
|
463
|
-
router.get(path, async function (_req, res) {
|
|
464
|
-
res.asyncEnd({
|
|
465
|
-
status: 200,
|
|
466
|
-
headers: {
|
|
467
|
-
["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
|
|
468
|
-
},
|
|
469
|
-
body: code
|
|
470
|
-
});
|
|
471
|
-
});
|
|
472
|
-
return resolve();
|
|
473
426
|
}
|
|
474
427
|
}
|
|
475
|
-
|
|
476
|
-
default:
|
|
477
|
-
if (file.ext === ".js" || file.ext === ".ts") {
|
|
428
|
+
case ".md": {
|
|
478
429
|
switch (file.subExt) {
|
|
479
|
-
case ".
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
case ".bundle":
|
|
484
|
-
case ".min": {
|
|
485
|
-
const code = await inflateJSX(file.filePath, {
|
|
486
|
-
embemedJSX: false,
|
|
487
|
-
minify: file.subExt === ".min" ? true : false,
|
|
488
|
-
useExport: false,
|
|
489
|
-
logger
|
|
490
|
-
});
|
|
491
|
-
const contentType = CONTENT_TYPE_MAP[".js"];
|
|
492
|
-
const path = join("/", dirname(relative(dir, file.filePath)), file.name + ".js");
|
|
430
|
+
case ".html": {
|
|
431
|
+
const code = await inflateMD2HTML(file.filePath, logger);
|
|
432
|
+
const contentType = CONTENT_TYPE_MAP[".html"];
|
|
433
|
+
const path = join("/", dirname(relative(dir, file.filePath)), file.name);
|
|
493
434
|
routeFileMap[file.filePath] = {
|
|
494
435
|
routes: [{
|
|
495
436
|
method: "GET",
|
|
496
437
|
path
|
|
497
438
|
}],
|
|
498
|
-
filePath: file.filePath,
|
|
499
439
|
service,
|
|
440
|
+
filePath: file.filePath,
|
|
500
441
|
previewMethod: "html"
|
|
501
442
|
};
|
|
502
443
|
|
|
@@ -533,80 +474,142 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
533
474
|
return resolve();
|
|
534
475
|
}
|
|
535
476
|
}
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
routeFileMap[file.filePath] = {
|
|
552
|
-
routes: [{
|
|
553
|
-
method: "GET",
|
|
554
|
-
path
|
|
555
|
-
}],
|
|
556
|
-
service,
|
|
557
|
-
filePath: file.filePath,
|
|
558
|
-
previewMethod: "html"
|
|
559
|
-
};
|
|
560
|
-
|
|
561
|
-
if (inflateDir) {
|
|
562
|
-
const inflatePath = join(inflateDir, service, "static", path);
|
|
563
|
-
mkdirSync(dirname(inflatePath), {
|
|
564
|
-
recursive: true
|
|
477
|
+
}
|
|
478
|
+
default:
|
|
479
|
+
if (file.ext === ".js" || file.ext === ".ts") {
|
|
480
|
+
switch (file.subExt) {
|
|
481
|
+
case ".ignore": {
|
|
482
|
+
logger.warn("ignoring [%s]", file.filePath);
|
|
483
|
+
return resolve();
|
|
484
|
+
}
|
|
485
|
+
case ".bundle":
|
|
486
|
+
case ".min": {
|
|
487
|
+
const code = await inflateJSX(file.filePath, {
|
|
488
|
+
embemedJSX: false,
|
|
489
|
+
minify: file.subExt === ".min" ? true : false,
|
|
490
|
+
useExport: false,
|
|
491
|
+
logger
|
|
565
492
|
});
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
contentType,
|
|
493
|
+
const contentType = CONTENT_TYPE_MAP[".js"];
|
|
494
|
+
const path = join("/", dirname(relative(dir, file.filePath)), file.name + ".js");
|
|
495
|
+
routeFileMap[file.filePath] = {
|
|
496
|
+
routes: [{
|
|
571
497
|
method: "GET",
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
498
|
+
path
|
|
499
|
+
}],
|
|
500
|
+
filePath: file.filePath,
|
|
501
|
+
service,
|
|
502
|
+
previewMethod: "html"
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
if (inflateDir) {
|
|
506
|
+
const inflatePath = join(inflateDir, service, "static", path);
|
|
507
|
+
mkdirSync(dirname(inflatePath), {
|
|
508
|
+
recursive: true
|
|
509
|
+
});
|
|
510
|
+
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
511
|
+
writeFileSync(inflatePath, code);
|
|
512
|
+
if (staticFileMap && inflateSea) {
|
|
513
|
+
staticFileMap[file.filePath] = {
|
|
514
|
+
contentType,
|
|
515
|
+
method: "GET",
|
|
516
|
+
filePath: file.filePath,
|
|
517
|
+
previewMethod: "html",
|
|
518
|
+
path,
|
|
519
|
+
body: Buffer.from(code),
|
|
520
|
+
inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
|
|
521
|
+
}
|
|
577
522
|
}
|
|
578
523
|
}
|
|
524
|
+
|
|
525
|
+
router.use(assertGlobalTampered);
|
|
526
|
+
router.get(path, async function (_req, res) {
|
|
527
|
+
res.asyncEnd({
|
|
528
|
+
status: 200,
|
|
529
|
+
headers: {
|
|
530
|
+
["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
|
|
531
|
+
},
|
|
532
|
+
body: code
|
|
533
|
+
});
|
|
534
|
+
});
|
|
535
|
+
return resolve();
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
} else if (file.ext === ".bundle") {
|
|
539
|
+
switch (file.subExt) {
|
|
540
|
+
case ".ignore": {
|
|
541
|
+
logger.warn("ignoring [%s]", file.filePath);
|
|
542
|
+
return resolve();
|
|
579
543
|
}
|
|
544
|
+
case ".css": {
|
|
545
|
+
const code = readFileSync(file.filePath).toString()
|
|
546
|
+
.split("\n")
|
|
547
|
+
.filter(c => c)
|
|
548
|
+
.filter(c => c.charAt(0) !== "#")
|
|
549
|
+
.map(cssPath => readFileSync(pathResolve(dirname(file.filePath), cssPath)).toString())
|
|
550
|
+
.join("\n");
|
|
551
|
+
const contentType = CONTENT_TYPE_MAP[".css"];
|
|
552
|
+
const path = join("/", dirname(relative(dir, file.filePath)), file.name);
|
|
553
|
+
routeFileMap[file.filePath] = {
|
|
554
|
+
routes: [{
|
|
555
|
+
method: "GET",
|
|
556
|
+
path
|
|
557
|
+
}],
|
|
558
|
+
service,
|
|
559
|
+
filePath: file.filePath,
|
|
560
|
+
previewMethod: "html"
|
|
561
|
+
};
|
|
580
562
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
563
|
+
if (inflateDir) {
|
|
564
|
+
const inflatePath = join(inflateDir, service, "static", path);
|
|
565
|
+
mkdirSync(dirname(inflatePath), {
|
|
566
|
+
recursive: true
|
|
567
|
+
});
|
|
568
|
+
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
569
|
+
writeFileSync(inflatePath, code);
|
|
570
|
+
if (staticFileMap && inflateSea) {
|
|
571
|
+
staticFileMap[file.filePath] = {
|
|
572
|
+
contentType,
|
|
573
|
+
method: "GET",
|
|
574
|
+
filePath: file.filePath,
|
|
575
|
+
previewMethod: "html",
|
|
576
|
+
path,
|
|
577
|
+
body: Buffer.from(code),
|
|
578
|
+
inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
router.use(assertGlobalTampered);
|
|
584
|
+
router.get(path, async function (_req, res) {
|
|
585
|
+
res.asyncEnd({
|
|
586
|
+
status: 200,
|
|
587
|
+
headers: {
|
|
588
|
+
["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
|
|
589
|
+
},
|
|
590
|
+
body: code
|
|
591
|
+
});
|
|
589
592
|
});
|
|
590
|
-
|
|
591
|
-
|
|
593
|
+
return resolve();
|
|
594
|
+
}
|
|
592
595
|
}
|
|
593
596
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
return resolve();
|
|
597
|
+
createStaticRoute(service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap);
|
|
598
|
+
return resolve();
|
|
597
599
|
|
|
600
|
+
}
|
|
601
|
+
} catch (e) {
|
|
602
|
+
logger.error("error with " + file.filePath);
|
|
603
|
+
logger.error(e);
|
|
604
|
+
errors.push({
|
|
605
|
+
filePath: file.filePath,
|
|
606
|
+
error: e
|
|
607
|
+
});
|
|
608
|
+
} finally {
|
|
609
|
+
return resolve();
|
|
598
610
|
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
logger.error(e);
|
|
602
|
-
errors.push({
|
|
603
|
-
filePath: file.filePath,
|
|
604
|
-
error: e
|
|
605
|
-
});
|
|
606
|
-
} finally {
|
|
607
|
-
return resolve();
|
|
608
|
-
}
|
|
609
|
-
})));
|
|
611
|
+
});
|
|
612
|
+
}
|
|
610
613
|
router.use(assertGlobalTampered);
|
|
611
614
|
return {
|
|
612
615
|
routeFileMap,
|