Nuxt (v3.x) 模块,用于使用中间件处理
.well-knownURI请参阅 https://www.iana.org/assignments/well-known-uris/well-known-uris.xhtml
⚠️ 仅在 SSR 模式下测试(未在 SSG 和 CSR 下测试)
Nuxt Well-Known 模块已与 Nuxt Devtools 集成。
security.txtchange-passwordcontent-uris@zadigetvoltaire/nuxt-well-known 依赖项添加到您的项目# Using pnpm
pnpm add -D @zadigetvoltaire/nuxt-well-known
# Using yarn
yarn add --dev @zadigetvoltaire/nuxt-well-known
# Using npm
npm install --save-dev @zadigetvoltaire/nuxt-well-known
@zadigetvoltaire/nuxt-well-known 添加到 nuxt.config.ts 的 modules 部分export default defineNuxtConfig({
modules: [
'@zadigetvoltaire/nuxt-well-known'
],
})
nuxtConfig.wellKnown 或 nuxtConfig.runtimeConfig.public.wellKnown 中添加配置此模块支持两种配置方式
wellKnown 键中export default defineNuxtConfig({
...
wellKnown: {
devtools: true,
securityTxt: {
disabled: false,
contacts: ['[email protected]'],
expires: new Date('2025-02-03')
},
changePassword: {
disabled: false,
redirectTo: 'https://example.com/password-recovery'
}
}
...
runtimeConfig: {
public: {
wellKnown: {
devtools: true,
securityTxt: {
disabled: false,
contacts: ['[email protected]'],
expires: new Date('2025-02-03').toISOString() // ⚠️ in runtime config, `expires` should be a string
},
changePassword: {
disabled: false,
redirectTo: 'https://example.com/password-recovery'
}
}
}
}
})
interface ModuleOptions {
/**
* Enable Nuxt Devtools integration
*
* @default true
*/
devtools?: boolean
securityTxt?: SecurityTxtOptions,
changePassword?: ChangePasswordOptions,
contentUris?: ContentUriOptions[],
}
security.txt此中间件将生成一个 security.txt 文件,可在 /.well-known/security.txt URI 下访问。
模型选项
type SecurityTxtOptions = {
disabled?: boolean;
contacts: string[]; // https://www.rfc-editor.org/rfc/rfc9116#section-2.5.3
expires: string | Date; // https://www.rfc-editor.org/rfc/rfc9116#section-2.5.5
encryption?: string[]; // https://www.rfc-editor.org/rfc/rfc9116#section-2.5.4
acknowledgments?: string[]; // https://www.rfc-editor.org/rfc/rfc9116#section-2.5.1
preferredLanguages?: string[]; // https://www.rfc-editor.org/rfc/rfc9116#section-2.5.8
canonical?: string[]; // https://www.rfc-editor.org/rfc/rfc9116#section-2.5.2
policy?: string[]; // https://www.rfc-editor.org/rfc/rfc9116#section-2.5.7
hiring?: string[]; // https://www.rfc-editor.org/rfc/rfc9116#section-2.5.6
}
change-password此中间件会将 /.well-known/change-password 的请求重定向到配置的目标 URL。
type ChangePasswordOptions = {
disabled?: boolean;
redirectTo: string;
}
content-uris使用此中间件,您可以生成带有内容的 URI
type ContentUriOptions = {
disabled?: boolean;
path: string;
content: string;
}
示例
// nuxt.config.ts
export default defineNuxtConfig({
modules: [
'@zadigetvoltaire/nuxt-well-known',
],
wellKnown: {
contentUris: [
{ path: 'apple-developer-merchantid-domain-association', content: 'merchantid' },
{ path: 'content-uri.txt', content: 'content-uri' }
]
}
})
将渲染
https://example.com/.well-known/apple-developer-merchantid-domain-association --> merchantidhttps://example.com/.well-known/content-uri.txt --> content-uri就是这样!您现在可以在 Nuxt 应用程序中使用 Nuxt Well-Known 啦 ✨
# Install dependencies, prepare apps & run dev server
make start
# Run dev server
pnpm dev
# Develop with playground, with bundled client ui
pnpm play:prod
# Run ESLint
pnpm lint
# Run Vitest
pnpm test
pnpm test:watch
⚠ 此命令只能在主分支上执行
此命令将
pnpm release
© Zadig&Voltaire 是 ZV FRANCE 的注册商标