@primate/core 0.1.1 → 0.1.3
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/package.json +1 -1
- package/src/build/targets/web.js +19 -2
- package/src/serve/hook/handle.js +2 -16
package/package.json
CHANGED
package/src/build/targets/web.js
CHANGED
|
@@ -29,6 +29,8 @@ export default async app => {
|
|
|
29
29
|
import join from "@rcompat/fs/join";
|
|
30
30
|
import stringify from "@rcompat/object/stringify";
|
|
31
31
|
import crypto from "@rcompat/crypto";
|
|
32
|
+
import { OK } from "@rcompat/http/status";
|
|
33
|
+
import { resolve } from "@rcompat/http/mime";
|
|
32
34
|
|
|
33
35
|
const encoder = new TextEncoder();
|
|
34
36
|
const hash = async (data, algorithm = "sha-384") => {
|
|
@@ -63,13 +65,28 @@ export default async app => {
|
|
|
63
65
|
const pages = {
|
|
64
66
|
${pages_str}
|
|
65
67
|
};
|
|
68
|
+
const buildroot = file(import.meta.url).join("..");
|
|
69
|
+
|
|
70
|
+
const serve_asset = asset => new Response(asset.stream(), {
|
|
71
|
+
status: OK,
|
|
72
|
+
headers: {
|
|
73
|
+
"Content-Type": resolve(asset.name),
|
|
74
|
+
},
|
|
75
|
+
});
|
|
66
76
|
|
|
67
77
|
const loader = {
|
|
68
78
|
page(name) {
|
|
69
79
|
return pages[name] ?? pages["${app.get("pages.app")}"];
|
|
70
80
|
},
|
|
71
|
-
asset(pathname) {
|
|
72
|
-
|
|
81
|
+
async asset(pathname) {
|
|
82
|
+
const root_asset = buildroot.join(\`client/\${pathname}\`);
|
|
83
|
+
if (await await root_asset.isFile) {
|
|
84
|
+
return serve_asset(root_asset);
|
|
85
|
+
}
|
|
86
|
+
const static_asset = buildroot.join(\`client/static/\${pathname}\`);
|
|
87
|
+
if (await static_asset.isFile) {
|
|
88
|
+
return serve_asset(static_asset);
|
|
89
|
+
}
|
|
73
90
|
},
|
|
74
91
|
};
|
|
75
92
|
const target = "web";
|
package/src/serve/hook/handle.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import log from "#log";
|
|
2
1
|
import client_error from "@primate/core/handler/error";
|
|
3
2
|
import cascade from "@rcompat/async/cascade";
|
|
4
3
|
import tryreturn from "@rcompat/async/tryreturn";
|
|
@@ -71,21 +70,8 @@ export default app => {
|
|
|
71
70
|
});
|
|
72
71
|
};
|
|
73
72
|
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
headers: {
|
|
77
|
-
"Content-Type": resolve(pathname),
|
|
78
|
-
// Etag: await path.modified(),
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const handle = async request => {
|
|
83
|
-
const { pathname } = request.url;
|
|
84
|
-
|
|
85
|
-
const asset = app.loader.asset(pathname)?.code;
|
|
86
|
-
|
|
87
|
-
return asset === undefined ? as_route(request) : as_asset(pathname, asset);
|
|
88
|
-
};
|
|
73
|
+
const handle = async request =>
|
|
74
|
+
(await app.loader.asset(request.url.pathname)) ?? as_route(request);
|
|
89
75
|
// first hook
|
|
90
76
|
const pass = (request, next) => next({
|
|
91
77
|
...request,
|