LoginSignup
2
2

More than 1 year has passed since last update.

nuxt-basic-auth-moduleで任意ページの認証を外す

Last updated at Posted at 2021-12-26

はじめに

Nuxtでnuxt-basic-auth-moduleを使ってBasic認証を実装。
このときApplication Load Balancerのヘルスチェックを通すため、一部のページのみ認証を外す必要があったのでやり方をメモ。
現時点でALBのヘルスチェックにheader情報の設定をすることはできないため、ヘルスチェック自体に認証情報を設定することはできない。

やりかた

matchプロパティで認証を外したいページのpathを設定する。正規表現も可能とのこと。

nuxt.config.js
export default {
  modules: [
    'nuxt-basic-auth-module',
  ],
  basic: {
    name: 'name',
    pass: 'pass',
    enabled: true,
    match: (req) => req.originalUrl !== '/healthcheck', //←これだけ
  }
}

↓一応、ALBの設定も書いておく。

cloudformation.yml
  TargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    DependsOn: PublicLoadBalancer
    Properties:
      HealthCheckIntervalSeconds: 30
      HealthCheckPath: /healthcheck #←ここにヘルスチェック先を設定
      HealthCheckProtocol: HTTP
      HealthCheckTimeoutSeconds: 10
      HealthyThresholdCount: 2
      TargetType: ip
      Name: !Ref 'EcsServiceName'
      Port: !Ref 'ContainerPort'
      Protocol: HTTP
      UnhealthyThresholdCount: 2
      VpcId: !Ref VpcId

参考

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2