Nuxt Nation カンファレンスが開催されます。11月12〜13日にご参加ください。

well-known
@zadigetvoltaire/nuxt-well-known

ミドルウェアを使用してwell-known URIを追加するNuxtモジュール

npm versionnpm downloadsLicenseNuxt

Nuxt Well-Known

ミドルウェアを使用して.well-known URIを処理するNuxt (v3.x) モジュール

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. nuxt.config.tsmodulesセクションに@zadigetvoltaire/nuxt-well-knownを追加します
export default defineNuxtConfig({
  modules: [
    '@zadigetvoltaire/nuxt-well-known'
  ],
})
  1. nuxtConfig.wellKnownまたはnuxtConfig.runtimeConfig.public.wellKnownで設定を追加します

このモジュールは、2つの構成方法をサポートしています

  • Nuxt設定のキーwellKnownで直接
  • パブリックruntimeConfig内:環境変数で設定を上書きし、複数の環境を処理するのに便利
export default defineNuxtConfig({
  ...
  wellKnown: {
    devtools: true,
    securityTxt: {
      disabled: false,
      contacts: ['me@example.com'],
      expires: new Date('2025-02-03')
    },
    changePassword: {
      disabled: false,
      redirectTo: 'https://example.com/password-recovery'
    }
  }
  ...
  runtimeConfig: {
    public: {
      wellKnown: {
        devtools: true,
        securityTxt: {
          disabled: false,
          contacts: ['me@example.com'],
          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

このミドルウェアは、/.well-known/security.txt URIで利用可能なsecurity.txtファイルを生成します。

モデルオプション

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. リリースコマンドを実行します

⚠ このコマンドはメインブランチでのみ実行する必要があります

このコマンドは以下を行います

  • CHANGELOG.mdを生成し、リリースコミットとともにプッシュします
  • パッケージのバージョンを上げます
  • 新しいタグを作成してプッシュします
  • ライブラリの公開パイプラインをトリガーするためのGitHubリリースを作成します
pnpm release

© Zadig&VoltaireはZV FRANCEの登録商標です