Interface: Server
Server-side application configuration.
See Server Config for usage details.
Exampleโ
import { app } from "@wasp.sh/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()
}