Loading...
Loading...
Nuxt adapter for embedding emulators directly in a Nuxt app via @emulators/adapter-nuxt. Use when the user needs to embed emulators in Nuxt, set up same-origin OAuth for preview deployments, create an emulate catch-all server route, configure persistence for embedded Nuxt emulators, or wrap nuxt.config with withEmulate. Triggers include "Nuxt emulator", "adapter-nuxt", "embedded emulator", "same-origin OAuth", "createEmulateHandler", "withEmulate", or any task requiring emulators inside a Nuxt app.
npx skill4agent add vercel-labs/emulate nuxt@emulators/adapter-nuxtnpm install @emulators/adapter-nuxt @emulators/github @emulators/google@emulators/*// server/routes/emulate/[...path].ts
import { createEmulateHandler } from '@emulators/adapter-nuxt'
import * as github from '@emulators/github'
import * as google from '@emulators/google'
export default defineEventHandler(createEmulateHandler({
services: {
github: {
emulator: github,
seed: {
users: [{ login: 'octocat', name: 'The Octocat' }],
repos: [{ owner: 'octocat', name: 'hello-world', auto_init: true }],
},
},
google: {
emulator: google,
seed: {
users: [{ email: 'test@example.com', name: 'Test User' }],
},
},
},
}))/emulate/github/**/emulate/google/**// nuxt.config.ts
import { withEmulate } from '@emulators/adapter-nuxt'
export default defineNuxtConfig(withEmulate({
// your normal Nuxt config
}))const baseUrl = process.env.NUXT_PUBLIC_SITE_URL ?? 'http://localhost:3000'
export const githubOAuth = {
clientId: 'any-value',
clientSecret: 'any-value',
authorizationUrl: `${baseUrl}/emulate/github/login/oauth/authorize`,
tokenUrl: `${baseUrl}/emulate/github/login/oauth/access_token`,
userInfoUrl: `${baseUrl}/emulate/github/user`,
}oauth_appsclient_idclient_secretredirect_uripersistenceimport { createEmulateHandler } from '@emulators/adapter-nuxt'
import * as github from '@emulators/github'
const storageAdapter = {
async load() { return await useStorage('emulate').getItem<string>('state') },
async save(data: string) { await useStorage('emulate').setItem('state', data) },
}
export default defineEventHandler(createEmulateHandler({
services: { github: { emulator: github } },
persistence: storageAdapter,
}))@emulators/coreimport { filePersistence } from '@emulators/core'
persistence: filePersistence('.emulate/state.json'),/emulate/github/login/oauth/authorize?client_id=...github/login/oauth/authorizeRequestactionhrefurl()LocationcreateEmulateHandler(config, options?)| Field | Type | Description |
|---|---|---|
| | Map of service name to emulator config |
| | Optional persistence adapter for state across cold starts |
EmulatorEntry| Field | Type | Description |
|---|---|---|
| | The emulator package, such as |
| | Seed data matching the service's config schema |
| Option | Type | Default | Description |
|---|---|---|---|
| | | Named catch-all route param |
| | detected | Path prefix where the catch-all route is mounted |
withEmulate(nuxtConfig)@emulators/coredefineNuxtConfignuxt.config.tsPersistenceAdapterinterface PersistenceAdapter {
load(): Promise<string | null>
save(data: string): Promise<void>
}