owebjs 1.3.2 → 1.3.4
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/utils/assignRoutes.js +12 -2
- package/dist/utils/generateFunctionFromTypescript.js +29 -2
- package/package.json +1 -1
- package/dist/uws_darwin_arm64_108.node +0 -0
- package/dist/uws_darwin_arm64_83.node +0 -0
- package/dist/uws_darwin_arm64_93.node +0 -0
- package/dist/uws_darwin_x64_108.node +0 -0
- package/dist/uws_darwin_x64_83.node +0 -0
- package/dist/uws_darwin_x64_93.node +0 -0
- package/dist/uws_linux_arm64_108.node +0 -0
- package/dist/uws_linux_arm64_83.node +0 -0
- package/dist/uws_linux_arm64_93.node +0 -0
- package/dist/uws_linux_x64_108.node +0 -0
- package/dist/uws_linux_x64_83.node +0 -0
- package/dist/uws_linux_x64_93.node +0 -0
- package/dist/uws_win32_x64_108.node +0 -0
- package/dist/uws_win32_x64_83.node +0 -0
- package/dist/uws_win32_x64_93.node +0 -0
|
@@ -246,7 +246,7 @@ const assignRoutes = /* @__PURE__ */ __name(async (oweb, directory, matchersDire
|
|
|
246
246
|
const files = await walk(directory);
|
|
247
247
|
const routes = await generateRoutes(files);
|
|
248
248
|
routesCache = routes;
|
|
249
|
-
|
|
249
|
+
function fallbackHandle(req, res) {
|
|
250
250
|
const vals = temporaryRequests[req.method.toLowerCase()];
|
|
251
251
|
const keys = Object.keys(vals);
|
|
252
252
|
if (!vals || !keys.length) {
|
|
@@ -261,7 +261,17 @@ const assignRoutes = /* @__PURE__ */ __name(async (oweb, directory, matchersDire
|
|
|
261
261
|
} else {
|
|
262
262
|
return send404(req, res);
|
|
263
263
|
}
|
|
264
|
-
}
|
|
264
|
+
}
|
|
265
|
+
__name(fallbackHandle, "fallbackHandle");
|
|
266
|
+
for (const element of [
|
|
267
|
+
"get",
|
|
268
|
+
"post",
|
|
269
|
+
"put",
|
|
270
|
+
"patch",
|
|
271
|
+
"delete"
|
|
272
|
+
]) {
|
|
273
|
+
oweb[element]("*", fallbackHandle);
|
|
274
|
+
}
|
|
265
275
|
for (const route of routes) {
|
|
266
276
|
assignSpecificRoute(oweb, route);
|
|
267
277
|
}
|
|
@@ -7,6 +7,12 @@ import generate from "@babel/generator";
|
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import babel from "@babel/core";
|
|
9
9
|
import { pathToFileURL } from "node:url";
|
|
10
|
+
import { writeFile, unlink } from "node:fs/promises";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { randomBytes } from "node:crypto";
|
|
13
|
+
import { createRequire } from "node:module";
|
|
14
|
+
import { error } from './logger.js';
|
|
15
|
+
const require2 = createRequire(import.meta.url);
|
|
10
16
|
async function generateFunctionFromTypescript(tsCode, filePath) {
|
|
11
17
|
const result = babel.transformSync(tsCode, {
|
|
12
18
|
presets: [
|
|
@@ -31,12 +37,33 @@ async function generateFunctionFromTypescript(tsCode, filePath) {
|
|
|
31
37
|
const absoluteDepPath = path.resolve(originalFileDir, resolvedPath);
|
|
32
38
|
const absoluteDepUrl = pathToFileURL(absoluteDepPath).href;
|
|
33
39
|
importSourceNode.value = absoluteDepUrl;
|
|
40
|
+
} else {
|
|
41
|
+
try {
|
|
42
|
+
const resolvedPath = require2.resolve(relativePath, {
|
|
43
|
+
paths: [
|
|
44
|
+
path.dirname(filePath)
|
|
45
|
+
]
|
|
46
|
+
});
|
|
47
|
+
const resolvedUrl = pathToFileURL(resolvedPath).href;
|
|
48
|
+
importSourceNode.value = resolvedUrl;
|
|
49
|
+
} catch (_) {
|
|
50
|
+
error(`Could not resolve module "${relativePath}". Please ensure it is installed.`, "HMR");
|
|
51
|
+
}
|
|
34
52
|
}
|
|
35
53
|
}
|
|
36
54
|
});
|
|
37
55
|
const { code: modifiedCode } = generate.default(ast);
|
|
38
|
-
const
|
|
39
|
-
const
|
|
56
|
+
const tempFileName = `oweb-temp-${randomBytes(16).toString("hex")}.mjs`;
|
|
57
|
+
const tempFilePath = path.join(tmpdir(), tempFileName);
|
|
58
|
+
let module;
|
|
59
|
+
try {
|
|
60
|
+
await writeFile(tempFilePath, modifiedCode, "utf-8");
|
|
61
|
+
const moduleUrl = pathToFileURL(tempFilePath).href;
|
|
62
|
+
module = await import(moduleUrl);
|
|
63
|
+
} finally {
|
|
64
|
+
await unlink(tempFilePath).catch(() => {
|
|
65
|
+
});
|
|
66
|
+
}
|
|
40
67
|
return module.default;
|
|
41
68
|
}
|
|
42
69
|
__name(generateFunctionFromTypescript, "generateFunctionFromTypescript");
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|