T
TanStack6mo ago
environmental-rose

Server seperation

We can use createServerFn to create functions which are callable but not directly part of the client bundle (as far as I understand). How do we create server side functions which are NOT callable by the client? For server side utilities and common functionality.
3 Replies
foreign-sapphire
foreign-sapphire6mo ago
You should be able to split correctly, but if you wanna be super sure you might include a vite plugin called vite-env-only and have it configured like this:
denyImports({
client: {
specifiers: [
"fs",
/^node:/,
"drizzle-orm",
"postgres",
"node-ray",
"Buffer",
"process",
"path",
"os",
"url",
"crypto",
"stream",
],
files: [
"**/.server/*",
"**/*.server.*",
"src/console/*",
"src/services/(?!.*types).*",
],
},
}),
denyImports({
client: {
specifiers: [
"fs",
/^node:/,
"drizzle-orm",
"postgres",
"node-ray",
"Buffer",
"process",
"path",
"os",
"url",
"crypto",
"stream",
],
files: [
"**/.server/*",
"**/*.server.*",
"src/console/*",
"src/services/(?!.*types).*",
],
},
}),
environmental-rose
environmental-roseOP6mo ago
Hey, thanks for suggestion! Will look into plugin and config.
foreign-sapphire
foreign-sapphire6mo ago
Your welcome, in this example it will deny importing to client those imports + the folders / files i mentioned there. like anything from services except the types, so this give me confidence that nothing on the services ( business logic ) should ever leak into the client

Did you find this page helpful?