Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: karthik2804 <[email protected]>
  • Loading branch information
karthik2804 committed Jan 21, 2025
1 parent 0cf1cc2 commit 64bde83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions templates/http-js/content/src/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { ResponseBuilder, Router } from "@fermyon/spin-sdk";

let router = Router();
router.get("*", (_, req, res) => { handleDefaultRoute(req, res) })
router.all("*", (_, req, res) => { notFound(req, res) })
// Modify this route or add additional ones to implement the component's API:
router.get("/hello/:name", (metadata, req, res) => { handleHelloRoute(req, res, metadata.params.name) });
// Default route that will be called for any routes not handled above:
router.all("*", (_, req, res) => { notFound(req, res) });

async function handleDefaultRoute(req, res) {
res.send("hello universe");
async function handleHelloRoute(req, res, name) {
res.send(`hello ${name}`);
}

async function notFound(req, res) {
res.status(404);
res.send("not found");
}

export async function handler(req, res) {
await router.handleRequest(req, res);
}
}
13 changes: 7 additions & 6 deletions templates/http-ts/content/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { ResponseBuilder, Router } from "@fermyon/spin-sdk";

let router = Router();
router.get("*", (_, req, res) => { handleDefaultRoute(req, res) })
router.all("*", (_, req, res) => { notFound(req, res) })
// Modify this route or add additional ones to implement the component's API:
router.get("/hello/:name", (metadata, req, res) => { handleHelloRoute(req, res, metadata.params.name) });
// Default route that will be called for any routes not handled above:
router.all("*", (_, req, res) => { notFound(req, res) });

async function handleDefaultRoute(req: Request, res: ResponseBuilder) {
res.send("hello universe");
async function handleHelloRoute(req: Request, res: ResponseBuilder, name: string) {
res.send(`hello ${name}`);
}

async function notFound(req: Request, res: ResponseBuilder) {
res.status(404);
res.send("not found");
}

export async function handler(req: Request, res: ResponseBuilder) {
await router.handleRequest(req, res);
}
}

0 comments on commit 64bde83

Please sign in to comment.