Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static files from html #69

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,25 @@ export class App {
}

// respondStatic returns Response with static file gotten from a path. If a given path didn't match, this method returns null.
//FIXME: does not get js file in public directory, linked from HTML -> responds from normal
private async respondStatic(path: string): Promise<Response | null> {
let fileInfo: Deno.FileInfo | null = null;
let staticFilePath = `${this.publicDir}${path}`;

try {
fileInfo = await stat(staticFilePath);
} catch (e) {
// Do nothing here.
}
if (fileInfo && fileInfo.isDirectory()) {
if (fileInfo && fileInfo.isDirectory) {
staticFilePath += "/index.html";
try {
fileInfo = await stat(staticFilePath);
} catch (e) {
fileInfo = null; // FileInfo is not needed any more.
}
}
if (!fileInfo || !fileInfo.isFile()) {
if (!fileInfo || !fileInfo.isFile) {
return null;
}
return [
Expand Down Expand Up @@ -166,6 +168,11 @@ export class App {
}
}

//FIXME: find proper solutin for files that are linked from HTML (would default to standard GET and not static)
if (path.endsWith(".js")) {
return null; // assume this is a static file
}

const ctx = { path, method, params };
const res = handler(ctx);
if (res instanceof Promise) {
Expand Down
2 changes: 1 addition & 1 deletion vendor/https/deno.land/std/encoding/utf8.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'https://deno.land/[email protected]/encoding/utf8.ts';
export * from "https://deno.land/[email protected]/encoding/utf8.ts";
2 changes: 1 addition & 1 deletion vendor/https/deno.land/std/flags/mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'https://deno.land/[email protected]/flags/mod.ts';
export * from "https://deno.land/[email protected]/flags/mod.ts";
2 changes: 1 addition & 1 deletion vendor/https/deno.land/std/http/server.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'https://deno.land/[email protected]/http/server.ts';
export * from "https://deno.land/[email protected]/http/server.ts";
2 changes: 1 addition & 1 deletion vendor/https/deno.land/std/testing/asserts.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'https://deno.land/[email protected]/testing/asserts.ts';
export * from "https://deno.land/[email protected]/testing/asserts.ts";