diff --git a/cli.ts b/cli.ts
index c7a1a4b7..1707b756 100644
--- a/cli.ts
+++ b/cli.ts
@@ -21,7 +21,10 @@ const output = `import { setup } from "../server.ts";
${files.map((file, i) => `import * as $${i} from "./pages${file}";`).join("\n")}
-setup([${files.map((_, i) => `$${i}`).join(", ")}], import.meta.url);
+setup([${
+ files.map((file, i) => `[$${i}, "./pages${file}"]`)
+ .join(", ")
+}], import.meta.url);
`;
Deno.writeTextFile("./server.ts", output);
diff --git a/example/pages/[name].tsx b/example/pages/[name].tsx
index cb62aaa0..f40c8cf3 100644
--- a/example/pages/[name].tsx
+++ b/example/pages/[name].tsx
@@ -10,7 +10,3 @@ export default function Home(props: PageProps) {
);
}
-
-export function self() {
- return import.meta.url;
-}
diff --git a/example/pages/index.tsx b/example/pages/index.tsx
index a9bcf9e4..0f7b1d68 100644
--- a/example/pages/index.tsx
+++ b/example/pages/index.tsx
@@ -3,7 +3,3 @@ import { h } from "../deps.ts";
export default function Home(props: {}) {
return
Hello World!
;
}
-
-export function self() {
- return import.meta.url;
-}
diff --git a/example/server.ts b/example/server.ts
index cce47e34..d4093aca 100644
--- a/example/server.ts
+++ b/example/server.ts
@@ -3,4 +3,4 @@ import { setup } from "../server.ts";
import * as $0 from "./pages/[name].tsx";
import * as $1 from "./pages/index.tsx";
-setup([$0, $1], import.meta.url);
+setup([[$0, "./pages/[name].tsx"], [$1, "./pages/index.tsx"]], import.meta.url);
diff --git a/src/server/mod.ts b/src/server/mod.ts
index 4781d02b..2cd435d5 100644
--- a/src/server/mod.ts
+++ b/src/server/mod.ts
@@ -1,7 +1,7 @@
import { createPages, PageModules } from "./routes.ts";
import { createServer } from "./server.ts";
-export function setup(pageModules: PageModules[], selfUrl: string) {
+export function setup(pageModules: [PageModules, string][], selfUrl: string) {
const baseUrl = new URL("./", selfUrl).href;
const pages = createPages(pageModules, baseUrl);
const app = createServer(pages);
diff --git a/src/server/routes.ts b/src/server/routes.ts
index 313afbe6..a947b4e1 100644
--- a/src/server/routes.ts
+++ b/src/server/routes.ts
@@ -4,7 +4,6 @@ import { PageProps } from "../runtime/types.ts";
export interface PageModules {
default: rt.ComponentType;
- self: () => string;
}
export interface Page {
@@ -14,10 +13,13 @@ export interface Page {
component: rt.ComponentType;
}
-export function createPages(pageModules: PageModules[], baseUrl: string): Page[] {
+export function createPages(
+ pageModules: [PageModules, string][],
+ baseUrl: string,
+): Page[] {
const pages: Page[] = [];
- for (const pageModule of pageModules) {
- const url = pageModule.self();
+ for (const [pageModule, self] of pageModules) {
+ const url = new URL(self, baseUrl).href;
if (!url.startsWith(baseUrl)) {
throw new TypeError("Page is not a child of the basepath.");
}