0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Nuxt3でSSGを生成するとindexが404になる問題

Last updated at Posted at 2023-05-07

備忘録として

環境

ホスティングサービス

  • AWS Amplify(S3)

フォルダ構成

/src
  +--.nuxt
  +--.output
  +--...

現象

ローカル開発下では問題なかったのに、Amplifyにデプロイするとトップページのみ404が帰ってきて真っ白な画面が表示される現象があった。
どうもこの現象はglobalなmiddlewareを作成した時ときのみ発生する模様。

Amplifyのビルドコマンドは以下:

version: 1
backend:
  phases:
    build:
      commands:
        - echo "********* IGNORE BACKEND CHECK/PUSH **********"
frontend:
  phases:
    preBuild:
      commands:
        - cd src
        - npm ci
    build:
      commands:
        - echo ${env}
        - npm run generate:${env}
  artifacts:
    baseDirectory: src/dist/
    files:
      - '**/*'
  cache:
    paths: []

対応

ビルド設定のデプロイファイルパスをsrc/dist/からsrc/.output/public/に変更すると解決した

version: 1
backend:
  phases:
    build:
      commands:
        - echo "********* IGNORE BACKEND CHECK/PUSH **********"
frontend:
  phases:
    preBuild:
      commands:
        - cd src
        - npm ci
    build:
      commands:
        - echo ${env}
        - npm run generate:${env}
  artifacts:
    baseDirectory: src/.output/public/
    files:
      - '**/*'
  cache:
    paths: []

メモ

Amplifyでバックエンドを使用していない場合、ビルドコマンドに適当なechoを入れるとデプロイ速度が若干改善する

backend:
  phases:
    build:
      commands:
        - echo "********* IGNORE BACKEND CHECK/PUSH **********"

バックエンドを使わないのはAmplifyの良さを潰しているような気もしなくもない。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?