summaryrefslogtreecommitdiff
path: root/packages/integrations/deno/src/server.ts
diff options
context:
space:
mode:
authorGravatar wulinsheng123 <409187100@qq.com> 2023-02-16 23:16:07 +0800
committerGravatar GitHub <noreply@github.com> 2023-02-16 09:16:07 -0600
commitef5cea4dc5c4ffa33bd57ea0886e6912afb24fec (patch)
tree681c11211a396616ac48fe0cf10fcbca96b521db /packages/integrations/deno/src/server.ts
parent0049fda62fa8650a0d250adb00a2c5d82679aeaf (diff)
downloadastro-ef5cea4dc5c4ffa33bd57ea0886e6912afb24fec.tar.gz
astro-ef5cea4dc5c4ffa33bd57ea0886e6912afb24fec.tar.zst
astro-ef5cea4dc5c4ffa33bd57ea0886e6912afb24fec.zip
Deno fix #6131 (#6248)
* 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>
Diffstat (limited to 'packages/integrations/deno/src/server.ts')
-rw-r--r--packages/integrations/deno/src/server.ts22
1 files changed, 16 insertions, 6 deletions
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',