remove need for export function self

This commit is contained in:
Luca Casonato
2021-05-08 03:12:56 +02:00
parent 303f4fd140
commit 9145711e2e
6 changed files with 12 additions and 15 deletions
+1 -1
View File
@@ -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);
+6 -4
View File
@@ -4,7 +4,6 @@ import { PageProps } from "../runtime/types.ts";
export interface PageModules {
default: rt.ComponentType<PageProps>;
self: () => string;
}
export interface Page {
@@ -14,10 +13,13 @@ export interface Page {
component: rt.ComponentType<PageProps>;
}
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.");
}