-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentry.ssr.js
40 lines (37 loc) · 1.09 KB
/
entry.ssr.js
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
import { render as r } from "@lit-labs/ssr";
import { DocBody } from "./pages/doc/index.js";
import { collectResult } from "@lit-labs/ssr/lib/render-result.js";
import { SettingsBody } from "./pages/settings/index.js";
import l10n from "./fluent.js";
/**
* @param {string} path
* @returns {Promise<Fred.Context<Rari.DocPage>>}
*/
async function fetch_from_rari(path) {
const external_url = `http://localhost:8083${path}`;
console.log(`using ${external_url}`);
return await (await fetch(external_url)).json();
}
/**
* @param {string} path
*/
export async function render(path) {
let result;
if (path.endsWith("settings")) {
result = r(SettingsBody());
} else {
const context = await fetch_from_rari(path);
context.l10n = await l10n(context.locale);
console.log("context", context.url);
result = r(DocBody(context));
}
return await collectResult(result);
}
/**
* @param {Rari.BuiltPage} context
*/
export async function renderWithContext(context) {
context.l10n = await l10n(context.locale);
const result = r(DocBody(context));
return await collectResult(result);
}