well-known
@zadigetvoltaire/nuxt-well-known

一個 Nuxt 模組,用於使用中介軟體新增 well-known URI

npm versionnpm downloadsLicenseNuxt

Nuxt Well-Known

Nuxt (v3.x) 模組,用於透過中介軟體處理 .well-known URI

參見 https://www.iana.org/assignments/well-known-uris/well-known-uris.xhtml

⚠️ 僅在 SSR 模式下測試(未在 SSG 和 CSR 下測試)

Nuxt Well-Known 模組已與 Nuxt Devtools 整合。

支援的 Well-Known URI

  1. security.txt
  2. change-password
  3. 包含內容的動態路由:content-uris

快速設定

  1. @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
  1. @zadigetvoltaire/nuxt-well-known 新增到 nuxt.config.tsmodules 部分
export default defineNuxtConfig({
  modules: [
    '@zadigetvoltaire/nuxt-well-known'
  ],
})
  1. nuxtConfig.wellKnownnuxtConfig.runtimeConfig.public.wellKnown 中新增配置

此模組支援兩種配置方式

  • 直接在 Nuxt 配置的 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 --> merchantid
  • https://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

釋出新版本

  1. 執行釋出命令

⚠ 此命令只能在 main 分支上執行

此命令將

  • 生成 CHANGELOG.md 並將其與釋出提交一起推送
  • 提升包版本
  • 建立並推送新標籤
  • 建立 GitHub 釋出以觸發庫釋出管道
pnpm release

© Zadig&Voltaire 是 ZV FRANCE 的註冊商標