forked from denoland/dotland
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
53 lines (44 loc) · 1.69 KB
/
main.ts
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
45
46
47
48
49
50
51
52
53
#!/usr/bin/env -S deno run --allow-read --allow-net --allow-env --allow-run --allow-hrtime --no-check --watch
// Copyright 2022 the Deno authors. All rights reserved. MIT license.
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" />
import { ServerContext } from "$fresh/server.ts";
import { Fragment, h } from "preact";
import { serve } from "$std/http/server.ts";
import { router } from "$router";
import { withLog } from "./util/ga_utils.ts";
import { setup } from "$doc_components/services.ts";
import manifest from "./fresh.gen.ts";
import options from "./options.ts";
import { routes as completionsV2Routes } from "./completions_v2.ts";
const docland = "https://doc.deno.land/";
await setup({
resolveHref(current, symbol) {
// FIXME(bartlomieju): special casing for std here is not ideal
if (symbol && current.startsWith("/std")) {
current = `https://deno.land${current}`;
}
return symbol ? `${docland}${current}/~/${symbol}` : current;
},
lookupHref(
current: string,
namespace: string | undefined,
symbol: string,
): string | undefined {
// FIXME(bartlomieju): special casing for std here is not ideal
if (current.startsWith("/std")) {
current = `https://deno.land${current}`;
}
return namespace
? `${docland}${current}/~/${namespace}.${symbol}`
: `${docland}${current}/~/${symbol}`;
},
runtime: { Fragment, h },
});
const ctx = await ServerContext.fromManifest(manifest, options);
const innerHandler = withLog(ctx.handler());
const handler = router(completionsV2Routes, innerHandler);
serve(handler);