Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit f5ec449f4df13c0f74613cb305c5f06c38778af6
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Wed Mar 6 10:44:27 2024 -0800

    update config to anticipate Vite updates, clearer experimental features, routesDir

commit c879a3c41cfd7ae6cf53fa3ccfff5c7b44a90a1f
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Tue Mar 5 16:28:14 2024 -0800

    fix FS router circular dep by moving import

commit 336aafb79ef42550f08a1c9b987c45960421d906
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Tue Mar 5 14:06:58 2024 -0800

    transparent errors and support http status forwarding in server fns

commit fbeed39064667ed95cc448121846c5c44c7b4eb1
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Tue Mar 5 12:40:41 2024 -0800

    bump vinxi plugins

commit a34dec859a2be52ffdb4ae691bb234a43a21d444
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Mon Mar 4 14:00:59 2024 -0800

    v0.6.1

commit db999705047582d208728ee6824ef07bcad24ede
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Mon Mar 4 13:37:55 2024 -0800

    update ts, fix #1346 flash types

commit 33a66aa5d5c71a3a0dee42a78952a75b1b38f320
Author: Patrick G <doeixd@gmail.com>
Date:   Mon Mar 4 15:29:40 2024 -0500

    Update package.json to include license (#1361)

    * Update package.json To include license

    JSDocs.io won't work without it.

    https://www.jsdocs.io/package/@solidjs/start

    * Create quiet-meals-heal.md

    ---------

    Co-authored-by: Ryan Carniato <ryansolid@gmail.com>

commit 9c4c7c01cefd7c85a7e858f3d2ca72f93d165138
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Mon Mar 4 12:25:53 2024 -0800

    update router

commit 28d77d3343f1aa53e477038ad4abede83329b03c
Author: Birk Skyum <74932975+birkskyum@users.noreply.github.com>
Date:   Mon Mar 4 18:23:32 2024 +0100

    Bump vinxi to ^0.3.9 everywhere (#1358)

    Co-authored-by: Ryan Carniato <ryansolid@gmail.com>

commit 6822b2e09753d38800b9ef7f7e7831452e48101a
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Mon Mar 4 09:20:09 2024 -0800

    unlock package.json again

commit 4889606a5833b64f3c4bdf9a6ccdef8f4ca3194c
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Thu Feb 29 10:59:25 2024 +0100

    temporary lock vinxi version

commit 5402007cb03000ef06b0cc3adef04a09a4b729bf
Author: Alexis H. Munsayac <alexis.munsayac@gmail.com>
Date:   Thu Feb 29 15:12:20 2024 +0800

    Fix refresh pragma (#1348)

    * Fix refresh pragma

    * Add changeset

    ---------

    Co-authored-by: Ryan Carniato <ryansolid@gmail.com>

commit dd37a5bed7d586f485bfe9e3992d44160948fac6
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Tue Feb 27 14:32:31 2024 -0800

    v0.6.0

commit 7d3355a400ddc45a12489a51f2bed6db7491578d
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Tue Feb 27 09:16:48 2024 -0800

    update vinxi, fix prerendering

commit 3634dd7599552cccc0e68b9eab0091bdcbfc2d85
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Mon Feb 26 12:07:20 2024 -0800

    configurable dev overlay

commit eecc8dcfdbfc66f313ff1bd79f2d424b719c13d3
Author: Nikhil Saraf <nsaraf98@gmail.com>
Date:   Mon Feb 26 21:10:44 2024 +0530

    Add @mdx-js/mdx dependency

commit c0973a0c96b523cd4fde3c4a30c1d00b59342c4f
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Sat Feb 24 09:24:12 2024 -0800

    dedupe plugins

commit 52e1f4427e9c76af0518ed05e210a4848af1f6db
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Fri Feb 23 16:00:29 2024 -0800

    move server rendering options to handler

commit 03d409a650db6f5a2ead6b2e8b84c74f2a74ab5b
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Fri Feb 23 15:40:40 2024 -0800

    fix nojs flash update auth/prisma examples

commit f80aedbea9ccdda29ea9a45fbba852f20aff65e1
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Fri Feb 23 12:25:23 2024 -0800

    vite.config -> app.config

commit a9cf09db7e00a643b686482b95f730f0d6ecc1be
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Thu Feb 22 15:29:53 2024 -0800

    v0.5.10

commit e3a0a09a2de989b111c20df1d5af0cd1130ca0e3
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Thu Feb 22 15:28:48 2024 -0800

    fix nojs return responses, fix throw single flight

commit fcdb8aa0ffe61a0190c15fa9d68bb3517909ac12
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Tue Feb 20 22:37:48 2024 -0800

    handler options as function, forward nonce to main scripts

commit 076aef995812eb59b379c5c017f64a303afda04e
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Tue Feb 20 16:08:38 2024 -0800

    fix #1276 - functions for plugins option

commit 58e3eac56474e62d929a0d934df05d6bfbc43e6a
Author: Ryan Carniato <ryansolid@gmail.com>
Date:   Tue Feb 20 15:24:34 2024 -0800

    update some versions

commit 33b471cb02d11858b4e0cc6ff156e5775f6ccb96
Author: Birk Skyum <birk.skyum@pm.me>
Date:   Wed Feb 14 10:10:20 2024 +0100

    Vinxi 0.2.1 -> 0.3.3

commit 36b7912
Merge: d149a60 6b08018
Author: Katja Lutz <katywings@users.noreply.github.com>
Date:   Tue Feb 20 23:31:06 2024 +0100

    Merge branch 'main' into vinxi-51-rpc-info

commit d149a60
Merge: 2aac293 f787f2b
Author: Katja Lutz <katywings@users.noreply.github.com>
Date:   Sun Feb 11 20:35:34 2024 +0100

    Merge branch 'main' into vinxi-51-rpc-info

commit 2aac293
Author: Katja Lutz <mail@katjalutz.ch>
Date:   Sun Dec 31 17:02:43 2023 +0100

    feat: implement getServerFunctionMeta

    Refs: nksaraf/vinxi#51
  • Loading branch information
ryansolid committed Mar 6, 2024
1 parent 28357e6 commit 3c9adc0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
23 changes: 23 additions & 0 deletions docs/routes/api/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@ In this example, regardless of whether we are rendering this on the server or in
### Serialization

Server functions allow the serialization of many different data types in the response. The full list is available [here](https://github.com/lxsmnsyc/seroval/blob/main/docs/compatibility.md#supported-types).

### Meta information

Depending on your hosting, the server function might be running in parallel on multiple cpu cores or workers. You can use `getServerFunctionMeta` to retrieve a function-specific `id`, which is stable across all instances.

Keep in mind: this `id` can and will change between builds!

```tsx twoslash
import { getServerFunctionMeta } from "@solidjs/start/server";

// or some in-memory db
const appCache: any = globalThis;

const counter = async () => {
"use server";
const { id } = getServerFunctionMeta()!;
const key = `counter_${id}`;
appCache[key] = appCache[key] ?? 0;
appCache[key]++;

return appCache[key] as number;
};
```
3 changes: 3 additions & 0 deletions packages/start/config/server-fns-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export function createServerReference(fn: Function, id: string, name: string) {
const ogEvt = getRequestEvent();
if (!ogEvt) throw new Error("Cannot call server function outside of a request");
const evt = cloneEvent(ogEvt);
evt.locals.serverFunctionMeta = {
id: id + "#" + name,
};
evt.serverOnly = true;
return provideRequestEvent(evt, () => {
return fn.apply(thisArg, args);
Expand Down
2 changes: 1 addition & 1 deletion packages/start/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { StartServer } from "./StartServer";
export { createHandler } from "./handler";
export { getServerFunctionMeta } from "./serverFunction";
export * from "./types";

6 changes: 6 additions & 0 deletions packages/start/server/serverFunction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { getRequestEvent } from "solid-js/web";
import type { ServerFunctionMeta } from "./types";

export function getServerFunctionMeta(): ServerFunctionMeta | undefined {
return getRequestEvent()?.locals.serverFunctionMeta;
}
4 changes: 4 additions & 0 deletions packages/start/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export interface APIHandler {
(event: APIEvent): Promise<any>;
}

export interface ServerFunctionMeta {
id: string;
}

declare module "solid-js/web" {
interface RequestEvent extends FetchEvent {
serverOnly?: boolean;
Expand Down

0 comments on commit 3c9adc0

Please sign in to comment.