Open kethan opened 3 months ago
Another deeply nested example.
app.js
import { Router } from "./itty";
import sub from './sub';
const app = Router();
app.use((req) => {
console.log("root!");
});
app.use("sub", sub);
app.get("/books", (req) => {
return ([
{
id: 1,
title: "Book 1",
author: "Author 1",
},
]);
});
app
.fetch({
url: "/sub/sub",
method: "GET",
})
.then(console.log)
.catch(console.error);
sub.js
import { Router } from "./itty";
import subsub from './subsub';
const app = Router();
app.use("/", (req) => {
console.log('sub root!');
})
app.use("sub", subsub)
app.get("/", (req) => {
return ("sub /get");
});
export default app;
subsub.js
import { Router } from "./itty";
const app = Router();
app.use("/", (req) => {
console.log('subsub root!');
})
.get("/", (req) => {
return ("subsub /get");
});
export default app;
Thanks @kethan - I'll take a look at this! It looks like a pretty clean implementation, but I'll have to weigh the bytes... at a glance, this looks like it adds quite a chunk to the final size...