你好吗?
我正在尝试使用s3和GitLab CI / CD在亚马逊中部署Next.js项目,但是当我重新加载路线不起作用时,网站会将您送回家。很奇怪我正在寻找解决方案,而且我正筋疲力尽。.所以,如果您能帮我忙,那将非常有帮助?
如果您需要更多信息,请告诉我
这是我的文件。
next.config.js
const fetch = require('isomorphic-unfetch')
module.exports = {
/* distDir: '_next', */
generateBuildId: async () => {
if (process.env.BUILD_ID) {
return process.env.BUILD_ID
} else {
return `${new Date().getTime()}`
}
},
exportPathMap: async function () {
const paths = {
'/': { page: '/' },
'/projects': { page: '/projects' },
'/admin': { page: '/admin' },
}
const res = await fetch('https://api.example')
const data = await res.json()
const orgs = data.map((entry) => entry)
orgs.forEach((org) => {
paths[`/org/${org.slug}`] = {
page: '/org/[slug]',
query: { slug: org.slug },
}
})
return paths
},
rules: [
{
enforce: 'pre',
test: /\.jsx?$/,
loader: 'eslint-loader',
exclude: /node_modules/,
},
{ test: /\.(js|jsx)$/, exclude: /node_modules/, loader: 'babel-loader' },
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=100000',
},
{
test: /\.scss$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
},
],
},
],
}
.gitlab-ci.yml
stages:
- build
- deploy
build:backend:
stage: build
image: node:12.13.1-alpine
script:
- cd backend
- yarn install
- yarn format:check
- yarn build
artifacts:
paths:
- backend/build
- backend/node_modules
only:
changes:
- backend/**/*
build:frontend:
stage: build
image: node:12.13.1-alpine
script:
- cd frontend
- yarn install
- yarn export
artifacts:
paths:
- frontend/out
only:
changes:
- frontend/**/*
deploy:backend:
stage: deploy
image: pahud/aws-sam-cli:latest
script:
- cd backend
- printenv > .env
- sam validate --template-file template.yaml
- sam package --template-file template.yaml --output-template-file packaged.yaml --s3-bucket gentem-backend --s3-prefix gt-api
- sam deploy --template-file packaged.yaml --stack-name gt-api --region us-east-1 --capabilities CAPABILITY_IAM
dependencies:
- build:backend
only:
refs:
- master
changes:
- backend/**/*
deploy:frontend:
stage: deploy
image: garland/aws-cli-docker:latest
script:
- cd frontend
- aws s3 cp ./out s3://gentem/ --recursive --acl public-read
- aws cloudfront create-invalidation --distribution-id ******** --paths '/*'
dependencies:
- build:frontend
only:
refs:
- master
changes:
- frontend/**/*