-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
44 lines (37 loc) · 1.39 KB
/
main.ts
File metadata and controls
44 lines (37 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { App, staticFiles } from "fresh";
import { define, type State } from "./utils.ts";
export const app = new App<State>();
// Check for GitHub token on startup
const githubToken = Deno.env.get("GITHUB_TOKEN");
if (!githubToken) {
console.warn(
"\n⚠️ WARNING: No GITHUB_TOKEN found in environment variables.\n" +
" GitHub API requests will be rate-limited (60 requests/hour).\n" +
" Create a .env file with GITHUB_TOKEN=your_token to increase limits.\n" +
" See .env.example for details.\n",
);
} else {
const maskedToken = `${githubToken.slice(0, 4)}...${githubToken.slice(-4)}`;
console.log(`✓ GitHub token found (${maskedToken}) - authenticated API requests enabled`);
}
app.use(staticFiles());
// Pass a shared value from a middleware
app.use(async (ctx) => {
ctx.state.shared = "hello";
return await ctx.next();
});
// this is the same as the /api/:name route defined via a file. feel free to delete this!
app.get("/api2/:name", (ctx) => {
const name = ctx.params.name;
return new Response(
`Hello, ${name.charAt(0).toUpperCase() + name.slice(1)}!`,
);
});
// this can also be defined via a file. feel free to delete this!
const exampleLoggerMiddleware = define.middleware((ctx) => {
console.log(`${ctx.req.method} ${ctx.req.url}`);
return ctx.next();
});
app.use(exampleLoggerMiddleware);
// Include file-system based routes here
app.fsRoutes();