Overview
createChipiServer provides a singleton ChipiServerSDK instance for server-side operations in Next.js. It ensures only one SDK instance exists across your application, with automatic config conflict detection.
Import everything from @chipi-stack/nextjs/server:
Setup
Create a shared server configuration file (e.g.lib/chipi-server.ts):
Functions
createChipiServer(config)
Creates or returns the singleton ChipiServerSDK instance.
Returns:
ChipiServerSDK
Config Conflict Detection
IfcreateChipiServer is called a second time with a different config, it throws an error instead of silently ignoring the new config. This prevents hard-to-debug issues where different parts of your app expect different configurations.
getChipiServer()
Returns the existing singleton instance. Throws if createChipiServer has not been called yet.
Returns: ChipiServerSDK
resetChipiServer()
Destroys the existing singleton instance so that a new one can be created with createChipiServer. Primarily useful for testing.
Usage in Server Components
Usage in Route Handlers
Usage in Server Actions
Related
- Backend SDK Quickstart — Full backend SDK reference
- Next.js Introduction — Client-side Next.js SDK setup
