Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/start/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"./client/spa": "./src/client/spa/index.tsx",
"./middleware": "./src/middleware/index.ts",
"./http": "./src/http/index.ts",
"./env": "./env.d.ts"
"./env": "./env.d.ts",
"./fns/server": "./src/fns/server.ts",
"./fns/client": "./src/fns/client.ts"
},
"publishConfig": {
"access": "public",
Expand All @@ -33,7 +35,9 @@
"./client/spa": "./dist/client/spa/index.jsx",
"./middleware": "./dist/middleware/index.js",
"./http": "./dist/http/index.js",
"./env": "./env.d.ts"
"./env": "./env.d.ts",
"./fns/server": "./dist/fns/server.js",
"./fns/client": "./dist/fns/client.js"
}
},
"dependencies": {
Expand Down
17 changes: 7 additions & 10 deletions packages/start/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { defu } from "defu";
import { globSync } from "node:fs";
import { extname, isAbsolute, join } from "node:path";
import { fileURLToPath } from "node:url";
import { normalizePath, type PluginOption } from "vite";
import type { PluginOption } from "vite";
import solid, { type Options as SolidOptions } from "vite-plugin-solid";
import { serverFunctionsPlugin } from "../directives/index.ts";
import { type ServerFunctionsOptions, serverFunctionsPlugin } from "../directives/index.ts";
import { DEFAULT_EXTENSIONS, VIRTUAL_MODULES, VITE_ENVIRONMENTS } from "./constants.ts";
import { devServer } from "./dev-server.ts";
import { type EnvPluginOptions, envPlugin } from "./env.ts";
import { envPlugin, type EnvPluginOptions } from "./env.ts";
import { SolidStartClientFileRouter, SolidStartServerFileRouter } from "./fs-router.ts";
import { fsRoutes } from "./fs-routes/index.ts";
import type { BaseFileSystemRouter } from "./fs-routes/router.ts";
Expand All @@ -33,6 +32,7 @@ export interface SolidStartOptions {
mode?: "js" | "json";
};
env?: EnvPluginOptions;
serverFunctions?: Pick<ServerFunctionsOptions, "filter">;
}

const absolute = (path: string, root: string) =>
Expand Down Expand Up @@ -182,13 +182,10 @@ export function solidStart(options?: SolidStartOptions): Array<PluginOption> {
serverFunctionsPlugin({
manifest: VIRTUAL_MODULES.serverFnManifest,
runtime: {
server: normalizePath(
fileURLToPath(new URL("../server/server-fns-runtime.ts", import.meta.url)),
),
client: normalizePath(
fileURLToPath(new URL("../server/server-runtime.ts", import.meta.url)),
),
server: '@solidjs/start/fns/server',
client: '@solidjs/start/fns/client',
},
filter: options?.serverFunctions?.filter,
}),
{
name: "solid-start:virtual-modules",
Expand Down
1 change: 1 addition & 0 deletions packages/start/src/directives/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function invalidateModules(
}
}


export function serverFunctionsPlugin(options: ServerFunctionsOptions): Plugin[] {
const filter = createFilter(
options.filter?.include || DEFAULT_INCLUDE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
BodyFormat,
extractBody,
getHeadersAndBody,
} from "./server-functions-shared.ts";
} from "./shared.ts";

let INSTANCE = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { sharedConfig } from "solid-js";
import { renderToString } from "solid-js/web";
import { provideRequestEvent } from "solid-js/web/storage";

import { getFetchEvent, mergeResponseHeaders } from "./fetchEvent.ts";
import { createPageEvent } from "./handler.ts";
import { getFetchEvent, mergeResponseHeaders } from "../server/fetchEvent.ts";
import { createPageEvent } from "../server/handler.ts";
import {
deserializeFromJSONString,
serializeToJSONStream,
Expand All @@ -16,12 +16,12 @@ import {
BodyFormat,
extractBody,
getHeadersAndBody,
} from "./server-functions-shared.ts";
} from "./shared.ts";
import "solidstart:server-fn-manifest";

import { getServerFunction } from "./server-fns.ts";
import type { FetchEvent, PageEvent } from "./types.ts";
import { getExpectedRedirectStatus } from "./util.ts";
import { getServerFunction } from "./registration.ts";
import type { FetchEvent, PageEvent } from "../server/types.ts";
import { getExpectedRedirectStatus } from "../server/util.ts";

export async function handleServerFunction(h3Event: H3Event) {
const event = getFetchEvent(h3Event);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getRequestEvent } from "solid-js/web";
import { provideRequestEvent } from "solid-js/web/storage";
import { registerServerFunction } from "./server-fns.ts";
import { registerServerFunction } from "./registration.ts";

interface Registration<T extends any[], R> {
id: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/start/src/server/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createRoutes } from "../router.tsx";
import { decorateHandler, decorateMiddleware } from "./fetchEvent.ts";
import { getSsrManifest } from "./manifest/ssr-manifest.ts";
import { matchAPIRoute } from "./routes.ts";
import { handleServerFunction } from "./server-functions-handler.ts";
import { handleServerFunction } from "../fns/handler.ts";
import type { APIEvent, FetchEvent, HandlerOptions, PageEvent } from "./types.ts";
import { getExpectedRedirectStatus } from "./util.ts";

Expand Down
Loading