-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: karthik2804 <[email protected]>
- Loading branch information
1 parent
0cf1cc2
commit 64bde83
Showing
2 changed files
with
14 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |