diff options
Diffstat (limited to 'packages/integrations/deno/src')
-rw-r--r-- | packages/integrations/deno/src/code-constant.ts | 2 | ||||
-rw-r--r-- | packages/integrations/deno/src/index.ts | 3 | ||||
-rw-r--r-- | packages/integrations/deno/src/server.ts | 22 |
3 files changed, 21 insertions, 6 deletions
diff --git a/packages/integrations/deno/src/code-constant.ts b/packages/integrations/deno/src/code-constant.ts new file mode 100644 index 000000000..bf272e397 --- /dev/null +++ b/packages/integrations/deno/src/code-constant.ts @@ -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);}` diff --git a/packages/integrations/deno/src/index.ts b/packages/integrations/deno/src/index.ts index 82da15188..891623ead 100644 --- a/packages/integrations/deno/src/index.ts +++ b/packages/integrations/deno/src/index.ts @@ -3,6 +3,7 @@ import esbuild from 'esbuild'; import * as fs from 'fs'; import * as npath from 'path'; import { fileURLToPath } from 'url'; +import * as CONSTANT from './code-constant' interface BuildConfig { server: URL; @@ -70,6 +71,8 @@ export default function createIntegration(args?: Options): AstroIntegration { 'astro:build:done': async () => { const entryUrl = new URL(_buildConfig.serverEntry, _buildConfig.server); const pth = fileURLToPath(entryUrl); + const content = await fs.readFileSync(pth, 'utf8') + await fs.writeFileSync(pth, `${CONSTANT.DEFAULTIMPORT}${content}${CONSTANT.DEFAULTSTART}`); await esbuild.build({ target: 'es2020', platform: 'browser', diff --git a/packages/integrations/deno/src/server.ts b/packages/integrations/deno/src/server.ts index 00e1c43db..ed358f2f0 100644 --- a/packages/integrations/deno/src/server.ts +++ b/packages/integrations/deno/src/server.ts @@ -1,10 +1,7 @@ // Normal Imports import type { SSRManifest } from 'astro'; 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 { port?: number; @@ -12,6 +9,7 @@ interface Options { start?: boolean; } +// @ts-ignore let _server: Server | 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 const url = new URL(request.url); 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 (fileResp.status == 404) { // Render the astro custom 404 page @@ -60,6 +69,7 @@ export function start(manifest: SSRManifest, options: Options) { }; const port = options.port ?? 8085; + // @ts-ignore _server = new Server({ port, hostname: options.hostname ?? '0.0.0.0', |