Loading...
Loading...
Compare original and translation side by side
@emulators/adapter-nuxt@emulators/adapter-nuxtnpm install @emulators/adapter-nuxt @emulators/github @emulators/google@emulators/*npm 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/**// 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
}))// nuxt.config.ts
import { withEmulate } from '@emulators/adapter-nuxt'
export default defineNuxtConfig(withEmulate({
// 你的常规Nuxt配置
}))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_uriconst 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_appsoauth_appsclient_idclient_secretredirect_uripersistencepersistenceimport { 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,
}))import { 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'),@emulators/coreimport { filePersistence } from '@emulators/core'
persistence: filePersistence('.emulate/state.json'),/emulate/github/login/oauth/authorize?client_id=...github/login/oauth/authorizeRequestactionhrefurl()Location/emulate/github/login/oauth/authorize?client_id=...github/login/oauth/authorizeRequestactionhrefurl()LocationcreateEmulateHandler(config, options?)createEmulateHandler(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 |
| 字段 | 类型 | 描述 |
|---|---|---|
| | 服务名称到模拟器配置的映射 |
| | 可选的持久化适配器,用于跨冷启动保留状态 |
EmulatorEntry| 字段 | 类型 | 描述 |
|---|---|---|
| | 模拟器包,例如 |
| | 匹配服务配置 schema 的预种子数据 |
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| | | 命名兜底路由参数 |
| | 自动检测 | 兜底路由挂载的路径前缀 |
withEmulate(nuxtConfig)withEmulate(nuxtConfig)@emulators/coredefineNuxtConfignuxt.config.ts@emulators/corenuxt.config.tsdefineNuxtConfigPersistenceAdapterPersistenceAdapterinterface PersistenceAdapter {
load(): Promise<string | null>
save(data: string): Promise<void>
}interface PersistenceAdapter {
load(): Promise<string | null>
save(data: string): Promise<void>
}