Interface: Server
Server-side application configuration.
See Server Config for usage details.
Example
import { app } from "@wasp/spec"
import { myMiddlewareConfigFn, mySetupFunction } from "./src/myServerSetupCode" with { type: "ref" }
export default app({
// ...
server: {
setupFn: mySetupFunction,
middlewareConfigFn: myMiddlewareConfigFn,
},
})
Properties
envValidationSchema?
optionalenvValidationSchema?:Reference<{_zod: {def:object; }; }>
Zod schema used to validate user-defined server environment variables on
startup. Wasp merges it with built-in validation for Wasp-defined env vars
when validating process.env. Define the schema with
defineEnvValidationSchema from wasp/env to make sure it is
type-checked.
Use reference imports when passing values from your app into the Wasp spec. If a direct import is not practical, use ref as a fallback.
For example:
import { serverEnvSchema } from './src/env' with { type: 'ref' }
See Env Vars.
middlewareConfigFn?
optionalmiddlewareConfigFn?:Reference<AnyFunction>
Function that customizes the global Express middleware stack. Affects all operations and APIs.
setupFn?
optionalsetupFn?:Reference<AnyFunction>
Async function called once on server start. Wasp awaits it before the
server accepts requests. Receives a context containing the Express app
and underlying http.Server, so you can register custom routes, set up
additional databases or WebSockets, or kick off scheduled jobs.
In TypeScript, you can type the function with the ServerSetupFn type
from wasp/server.
Example
import { type ServerSetupFn } from "wasp/server"
export const mySetupFunction: ServerSetupFn = async () => {
await setUpSomeResource()
}
traceDeps?
optionaltraceDeps?:string[]
Extra packages to copy into the server's Docker image.
The Docker image contains only the files the server imports. A package
that loads files in a non-standard way (for example, static assets it
serves from its own folder) can miss some of them. Each entry is a package name with
an optional prefix or suffix, the same syntax as Nitro's traceDeps:
"pkg"traces the package even when the server doesn't import it."pkg*"copies all of the package's files."!pkg"stops copying all files of a package Wasp copies fully by default.
We use nf3, which finds most of the files your dependencies need by default. Only use this setting if you've confirmed a necessary file is missing.
Example
traceDeps: ["swagger-ui-dist*"]
See
- https://wasp.sh/docs/deployment/methods/overview#missing-files-in-the-docker-image
- https://nitro.build/config#tracedeps for the entry syntax.
- https://github.com/unjs/nf3/blob/main/src/db.ts for the packages copied in full by default.