feat: add api routes (#11)
This commit adds API routes. These routes are located in the ./pages/api/ directory. Each file in there will have it's default export invoked for HTTP calls to the corresponding route.
This commit is contained in:
+10
-2
@@ -1,11 +1,15 @@
|
||||
import { extname, oak } from "./deps.ts";
|
||||
import { Bundler } from "./bundle.ts";
|
||||
import { render } from "./render.ts";
|
||||
import { Page } from "./page.ts";
|
||||
import { ApiRoute, Page } from "./routes.ts";
|
||||
import { BUILD_ID, INTERNAL_PREFIX, JS_PREFIX } from "./constants.ts";
|
||||
|
||||
/** This function installs all routes required by fresh onto an oak router. */
|
||||
export function installRoutes(router: oak.Router, pages: Page[]) {
|
||||
export function installRoutes(
|
||||
router: oak.Router,
|
||||
pages: Page[],
|
||||
apiRoutes: ApiRoute[],
|
||||
) {
|
||||
for (const page of pages) {
|
||||
router.get<Record<string, string>>(page.route, (ctx) => {
|
||||
ctx.response.status = 200;
|
||||
@@ -14,6 +18,10 @@ export function installRoutes(router: oak.Router, pages: Page[]) {
|
||||
});
|
||||
}
|
||||
|
||||
for (const apiRoute of apiRoutes) {
|
||||
router.all(apiRoute.route, apiRoute.handler);
|
||||
}
|
||||
|
||||
const internal = internalRouter(pages);
|
||||
|
||||
router.use(
|
||||
|
||||
Reference in New Issue
Block a user