-
Notifications
You must be signed in to change notification settings - Fork 417
Expand file tree
/
Copy pathindex.tsx
More file actions
44 lines (42 loc) · 1.39 KB
/
index.tsx
File metadata and controls
44 lines (42 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 { Title } from "@solidjs/meta";
import { json } from "@solidjs/router";
import { clientOnly, GET } from "@solidjs/start";
import { getServerFunctionMeta } from "@solidjs/start/server";
import { getRequestEvent, isServer } from "@solidjs/web";
import Counter from "~/components/Counter";
const BreaksOnServer = clientOnly(() => import("~/components/BreaksOnServer"));
const hello = GET(async (name: string) => {
"use server";
const e = getRequestEvent()!;
const { id } = getServerFunctionMeta()!;
console.log("ID", id, e.locals.foo);
return json(
{ hello: new Promise<string>(r => setTimeout(() => r(name), 1000)) },
{ headers: { "cache-control": "max-age=60" } },
);
});
export default function Home() {
hello("John").then(async v => {
console.log(v);
console.log(await v.hello);
});
const port = isServer ? new URL(getRequestEvent()!.request.url).port : location.port;
fetch(`http://localhost:${port}${import.meta.env.BASE_URL}/unknown`, {
headers: { Accept: "application/json" },
}).then(async res => console.log(await res.json()));
return (
<main>
<Title>Hello World</Title>
<h1>Hello world!</h1>
<Counter />
<BreaksOnServer />
<p>
Visit{" "}
<a href="https://start.solidjs.com" target="_blank">
start.solidjs.com
</a>{" "}
to learn how to build SolidStart apps.
</p>
</main>
);
}