-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reference: <https://deno.land/x/[email protected]>
- Loading branch information
1 parent
05452f5
commit 21a6db9
Showing
6 changed files
with
44 additions
and
5 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
GOOGLE_ANALYTICS_ID="" |
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 +1,2 @@ | ||
generated | ||
.env |
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
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 |
---|---|---|
|
@@ -15,11 +15,12 @@ | |
"highlight.js": "npm:highlight.js@^11.9.0", | ||
"markdown-it": "npm:markdown-it@^14.1.0", | ||
"markdown-it-anchor": "npm:markdown-it-anchor@^9.0.0", | ||
"simplex-noise": "npm:simplex-noise@^4.0.1" | ||
"simplex-noise": "npm:simplex-noise@^4.0.1", | ||
"ga": "https://deno.land/x/[email protected]/mod.ts" | ||
}, | ||
"tasks": { | ||
"generate": "deno run --allow-read --allow-write codegen/codegen.ts", | ||
"start": "deno run --allow-net --allow-read main.ts generated", | ||
"start": "deno run --allow-net --allow-read --allow-env --env main.ts generated", | ||
"molt": "deno run -A jsr:@molt/cli -w" | ||
}, | ||
"fmt": { | ||
|
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { createReporter } from "ga"; | ||
|
||
const GOOGLE_ANALYTICS_ID = Deno.env.get("GOOGLE_ANALYTICS_ID")!; | ||
|
||
const ga = createReporter({ id: GOOGLE_ANALYTICS_ID }); | ||
|
||
export function useGoogleAnalytics( | ||
fn: ( | ||
request: Request, | ||
info: Deno.ServeHandlerInfo<Deno.NetAddr>, | ||
) => Response | Promise<Response>, | ||
) { | ||
return async function ( | ||
request: Request, | ||
info: Deno.ServeHandlerInfo<Deno.NetAddr>, | ||
) { | ||
let error; | ||
let response: Response; | ||
const start = performance.now(); | ||
try { | ||
response = await fn(request, info); | ||
} catch (e) { | ||
error = e; | ||
} finally { | ||
ga(request, info, response!, start, error); | ||
} | ||
|
||
return response!; | ||
}; | ||
} |
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,3 +1,6 @@ | ||
import { serveDir } from "@std/http/file-server"; | ||
import { useGoogleAnalytics } from "./google-analytics.ts"; | ||
|
||
Deno.serve((request) => serveDir(request, { fsRoot: Deno.args[0] ?? "." })); | ||
Deno.serve(useGoogleAnalytics( | ||
(request) => serveDir(request, { fsRoot: Deno.args[0] ?? "." }), | ||
)); |