@alteran/astro 0.1.9 → 0.1.11
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/index.js +55 -0
- package/package.json +1 -1
- package/src/_worker.ts +2 -1
- package/src/entrypoints/server.ts +19 -0
- package/src/lib/jwt.ts +2 -2
package/index.js
CHANGED
|
@@ -62,6 +62,7 @@ export default function alteran(options = {}) {
|
|
|
62
62
|
|
|
63
63
|
const middlewareEntrypoint = resolvePackagePath('./src/middleware.ts');
|
|
64
64
|
const serverEntrypoint = resolvePackagePath('./src/_worker.ts');
|
|
65
|
+
const cloudflareServerAdapter = resolvePackagePath('./src/entrypoints/server.ts');
|
|
65
66
|
|
|
66
67
|
const routes = CORE_ROUTES.slice();
|
|
67
68
|
if (includeRootEndpoint) {
|
|
@@ -79,6 +80,60 @@ export default function alteran(options = {}) {
|
|
|
79
80
|
updateConfig({ output: 'server' });
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
const existingAlias = config.vite?.resolve?.alias ?? [];
|
|
84
|
+
const aliasArray = Array.isArray(existingAlias)
|
|
85
|
+
? existingAlias.slice()
|
|
86
|
+
: Object.entries(existingAlias).map(([find, replacement]) => ({ find, replacement }));
|
|
87
|
+
|
|
88
|
+
const hasCloudflareAlias = aliasArray.some(
|
|
89
|
+
(entry) => entry && entry.find === '@astrojs/cloudflare/entrypoints/server.js'
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
if (!hasCloudflareAlias) {
|
|
93
|
+
aliasArray.push({
|
|
94
|
+
find: '@astrojs/cloudflare/entrypoints/server.js',
|
|
95
|
+
replacement: cloudflareServerAdapter,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const vitePlugins = Array.isArray(config.vite?.plugins)
|
|
100
|
+
? config.vite.plugins.slice().filter(Boolean)
|
|
101
|
+
: [];
|
|
102
|
+
|
|
103
|
+
vitePlugins.push({
|
|
104
|
+
name: 'alteran-sequencer-export',
|
|
105
|
+
enforce: 'post',
|
|
106
|
+
apply: 'build',
|
|
107
|
+
transform(code, id) {
|
|
108
|
+
if (!id.includes('@astrojs-ssr-virtual-entry')) return null;
|
|
109
|
+
if (!code.includes('const _exports = createExports')) return null;
|
|
110
|
+
if (code.includes("const Sequencer = _exports['Sequencer'];")) return null;
|
|
111
|
+
|
|
112
|
+
const replacedInit = code.replace(
|
|
113
|
+
'const __astrojsSsrVirtualEntry = _exports.default;',
|
|
114
|
+
"const Sequencer = _exports['Sequencer'];\nconst __astrojsSsrVirtualEntry = _exports.default;"
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
if (replacedInit === code) return null;
|
|
118
|
+
|
|
119
|
+
const replacedExport = replacedInit.replace(
|
|
120
|
+
'export { __astrojsSsrVirtualEntry as default, pageMap };',
|
|
121
|
+
'export { Sequencer, __astrojsSsrVirtualEntry as default, pageMap };'
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return { code: replacedExport, map: null };
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
updateConfig({
|
|
129
|
+
vite: {
|
|
130
|
+
resolve: {
|
|
131
|
+
alias: aliasArray,
|
|
132
|
+
},
|
|
133
|
+
plugins: vitePlugins,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
|
|
82
137
|
if (injectServerEntry) {
|
|
83
138
|
if (config.build?.serverEntry && config.build.serverEntry !== serverEntrypoint) {
|
|
84
139
|
logger.info(
|
package/package.json
CHANGED
package/src/_worker.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SSRManifest } from 'astro';
|
|
2
|
+
import { App } from 'astro/app';
|
|
3
|
+
import { handle } from '@astrojs/cloudflare/handler';
|
|
4
|
+
import { Sequencer } from '../worker/sequencer';
|
|
5
|
+
|
|
6
|
+
export function createExports(manifest: SSRManifest) {
|
|
7
|
+
const app = new App(manifest);
|
|
8
|
+
const fetch = async (request: Request, env: unknown, context: unknown) => {
|
|
9
|
+
// Delegate to the Cloudflare adapter handler while preserving Alteran additions.
|
|
10
|
+
return await handle(manifest, app, request, env as any, context as any);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
default: { fetch },
|
|
15
|
+
Sequencer,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { Sequencer };
|
package/src/lib/jwt.ts
CHANGED
|
@@ -111,9 +111,9 @@ async function eddsaJwtSign(payload: any, env: Env): Promise<string> {
|
|
|
111
111
|
// Decode base64 private key
|
|
112
112
|
const keyBytes = b64urlDecode(keyData);
|
|
113
113
|
const key = await crypto.subtle.importKey(
|
|
114
|
-
'
|
|
114
|
+
'pkcs8',
|
|
115
115
|
keyBytes,
|
|
116
|
-
{ name: 'Ed25519'
|
|
116
|
+
{ name: 'Ed25519' } as any,
|
|
117
117
|
false,
|
|
118
118
|
['sign']
|
|
119
119
|
);
|