Skip to main content
Version: Next

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?​

optional envValidationSchema?: 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?​

optional middlewareConfigFn?: Reference<AnyFunction>

Function that customizes the global Express middleware stack. Affects all operations and APIs.

See Configuring Middleware.


setupFn?​

optional setupFn?: 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?​

optional traceDeps?: 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​