* fix: #6131 * fix: delete * update code * fix: fix bug * add some tests * fix route error * delete comment * delete trash code --------- Co-authored-by: wuls <linsheng.wu@beantechs.com>
This commit is contained in:
parent
0049fda62f
commit
ef5cea4dc5
7 changed files with 65 additions and 12 deletions
6
.changeset/funny-seahorses-compare.md
Normal file
6
.changeset/funny-seahorses-compare.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
'@astrojs/deno': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Deno SSR with prerender=true complains about invalid URL scheme
|
|
@ -36,7 +36,7 @@ export function vitePluginSSR(internals: BuildInternals, adapter: AstroAdapter):
|
||||||
},
|
},
|
||||||
load(id) {
|
load(id) {
|
||||||
if (id === resolvedVirtualModuleId) {
|
if (id === resolvedVirtualModuleId) {
|
||||||
return `import * as adapter from '${adapter.serverEntrypoint}';
|
return `import * as _adapter from '${adapter.serverEntrypoint}';
|
||||||
import * as _main from '${pagesVirtualModuleId}';
|
import * as _main from '${pagesVirtualModuleId}';
|
||||||
import { deserializeManifest as _deserializeManifest } from 'astro/app';
|
import { deserializeManifest as _deserializeManifest } from 'astro/app';
|
||||||
const _manifest = Object.assign(_deserializeManifest('${manifestReplace}'), {
|
const _manifest = Object.assign(_deserializeManifest('${manifestReplace}'), {
|
||||||
|
@ -47,7 +47,7 @@ const _args = ${adapter.args ? JSON.stringify(adapter.args) : 'undefined'};
|
||||||
export * from '${pagesVirtualModuleId}';
|
export * from '${pagesVirtualModuleId}';
|
||||||
${
|
${
|
||||||
adapter.exports
|
adapter.exports
|
||||||
? `const _exports = adapter.createExports(_manifest, _args);
|
? `const _exports = _adapter.createExports(_manifest, _args);
|
||||||
${adapter.exports
|
${adapter.exports
|
||||||
.map((name) => {
|
.map((name) => {
|
||||||
if (name === 'default') {
|
if (name === 'default') {
|
||||||
|
@ -61,11 +61,13 @@ export { _default as default };`;
|
||||||
`
|
`
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
|
export const adapter = _adapter
|
||||||
|
${adapter.name !== '@astrojs/deno' ? `
|
||||||
const _start = 'start';
|
const _start = 'start';
|
||||||
if(_start in adapter) {
|
if(_start in _adapter) {
|
||||||
adapter[_start](_manifest, _args);
|
_adapter[_start](_manifest, _args);
|
||||||
}`;
|
}`: ''}`;
|
||||||
}
|
}
|
||||||
return void 0;
|
return void 0;
|
||||||
},
|
},
|
||||||
async generateBundle(_opts, bundle) {
|
async generateBundle(_opts, bundle) {
|
||||||
|
|
2
packages/integrations/deno/src/code-constant.ts
Normal file
2
packages/integrations/deno/src/code-constant.ts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
export const DEFAULTIMPORT = `import { Server } from "https://deno.land/std@0.167.0/http/server.ts"; \n import { fetch } from "https://deno.land/x/file_fetch/mod.ts";\nimport { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";`
|
||||||
|
export const DEFAULTSTART = `const _start = 'start'; \n if(_start in adapter) { \nadapter[_start](_manifest, _args);}`
|
|
@ -3,6 +3,7 @@ import esbuild from 'esbuild';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as npath from 'path';
|
import * as npath from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
import * as CONSTANT from './code-constant'
|
||||||
|
|
||||||
interface BuildConfig {
|
interface BuildConfig {
|
||||||
server: URL;
|
server: URL;
|
||||||
|
@ -70,6 +71,8 @@ export default function createIntegration(args?: Options): AstroIntegration {
|
||||||
'astro:build:done': async () => {
|
'astro:build:done': async () => {
|
||||||
const entryUrl = new URL(_buildConfig.serverEntry, _buildConfig.server);
|
const entryUrl = new URL(_buildConfig.serverEntry, _buildConfig.server);
|
||||||
const pth = fileURLToPath(entryUrl);
|
const pth = fileURLToPath(entryUrl);
|
||||||
|
const content = await fs.readFileSync(pth, 'utf8')
|
||||||
|
await fs.writeFileSync(pth, `${CONSTANT.DEFAULTIMPORT}${content}${CONSTANT.DEFAULTSTART}`);
|
||||||
await esbuild.build({
|
await esbuild.build({
|
||||||
target: 'es2020',
|
target: 'es2020',
|
||||||
platform: 'browser',
|
platform: 'browser',
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
// Normal Imports
|
// Normal Imports
|
||||||
import type { SSRManifest } from 'astro';
|
import type { SSRManifest } from 'astro';
|
||||||
import { App } from 'astro/app';
|
import { App } from 'astro/app';
|
||||||
// @ts-ignore
|
|
||||||
import { Server } from 'https://deno.land/std@0.167.0/http/server.ts';
|
|
||||||
// @ts-ignore
|
|
||||||
import { fetch } from 'https://deno.land/x/file_fetch/mod.ts';
|
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
port?: number;
|
port?: number;
|
||||||
|
@ -12,6 +9,7 @@ interface Options {
|
||||||
start?: boolean;
|
start?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
let _server: Server | undefined = undefined;
|
let _server: Server | undefined = undefined;
|
||||||
let _startPromise: Promise<void> | undefined = undefined;
|
let _startPromise: Promise<void> | undefined = undefined;
|
||||||
|
|
||||||
|
@ -39,8 +37,19 @@ export function start(manifest: SSRManifest, options: Options) {
|
||||||
// try to fetch a static file instead
|
// try to fetch a static file instead
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const localPath = new URL('./' + app.removeBase(url.pathname), clientRoot);
|
const localPath = new URL('./' + app.removeBase(url.pathname), clientRoot);
|
||||||
const fileResp = await fetch(localPath.toString());
|
const stringLocalPath = localPath.toString();
|
||||||
|
// @ts-ignore
|
||||||
|
const extendName = fileExtension(stringLocalPath);
|
||||||
|
const fileResp = await fetch(
|
||||||
|
!extendName
|
||||||
|
? `${
|
||||||
|
stringLocalPath.endsWith('/')
|
||||||
|
? `${stringLocalPath}index.html`
|
||||||
|
: `${stringLocalPath}/index.html`
|
||||||
|
}`
|
||||||
|
: stringLocalPath
|
||||||
|
);
|
||||||
|
|
||||||
// If the static file can't be found
|
// If the static file can't be found
|
||||||
if (fileResp.status == 404) {
|
if (fileResp.status == 404) {
|
||||||
// Render the astro custom 404 page
|
// Render the astro custom 404 page
|
||||||
|
@ -60,6 +69,7 @@ export function start(manifest: SSRManifest, options: Options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const port = options.port ?? 8085;
|
const port = options.port ?? 8085;
|
||||||
|
// @ts-ignore
|
||||||
_server = new Server({
|
_server = new Server({
|
||||||
port,
|
port,
|
||||||
hostname: options.hostname ?? '0.0.0.0',
|
hostname: options.hostname ?? '0.0.0.0',
|
||||||
|
|
|
@ -143,3 +143,24 @@ Deno.test({
|
||||||
sanitizeResources: false,
|
sanitizeResources: false,
|
||||||
sanitizeOps: false,
|
sanitizeOps: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: 'perendering',
|
||||||
|
permissions: defaultTestPermissions,
|
||||||
|
async fn() {
|
||||||
|
await startApp(async (baseUrl: URL) => {
|
||||||
|
const resp = await fetch(new URL('perendering', baseUrl));
|
||||||
|
assertEquals(resp.status, 200);
|
||||||
|
|
||||||
|
|
||||||
|
const html = await resp.text();
|
||||||
|
assert(html);
|
||||||
|
|
||||||
|
const doc = new DOMParser().parseFromString(html, `text/html`);
|
||||||
|
const h1 = doc!.querySelector('h1');
|
||||||
|
assertEquals(h1!.innerText, 'test');
|
||||||
|
});
|
||||||
|
},
|
||||||
|
sanitizeResources: false,
|
||||||
|
sanitizeOps: false,
|
||||||
|
});
|
||||||
|
|
9
packages/integrations/deno/test/fixtures/basics/src/pages/perendering.astro
vendored
Normal file
9
packages/integrations/deno/test/fixtures/basics/src/pages/perendering.astro
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
export const prerender = true;
|
||||||
|
---
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<h1>test</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Reference in a new issue