-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
22 lines (18 loc) · 680 Bytes
/
main.ts
File metadata and controls
22 lines (18 loc) · 680 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { App, staticFiles } from "fresh";
import { type State } from "./utils.ts";
import { listProjects } from "./db/queries.ts";
export const app = new App<State>();
app.use(staticFiles());
// Inject the project list into every request's state so the nav
// can render the project switcher without each page fetching it separately.
app.use(async (ctx) => {
// Skip for static assets and API routes to avoid unnecessary DB hits
const { pathname } = ctx.url;
if (!pathname.startsWith("/api/") && !pathname.startsWith("/_fresh/")) {
ctx.state.projects = await listProjects();
} else {
ctx.state.projects = [];
}
return await ctx.next();
});
app.fsRoutes();