amazon-web-services - NextJS 在 AWS Elasticbeanstalk 上返回 502 错误
问题描述
我正在尝试使用 Codepipeline 在 AWS Elasticbeanstalk 上配置我的 nextjs 项目。我已经安装了 Express.js 来使用 EBS 部署它。
我的 server.js(在根文件夹中)
const express = require('express');
const next = require('next');
const dev = process.env.NODE_ENV !== 'production';
const port = process.env.PORT || 3000;
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare()
.then(() => {
const server = express();
server.get('/test', (req, res) => {
res.send('Hello from express!', 200);
});
server.get('*', (req, res) => {
return handle(req, res);
});
server.listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`);
});
})
.catch((ex) => {
console.error(ex.stack);
process.exit(1);
});
这是我的 CodeBuild 的 buildspec.yml:
版本:0.2
phases:
install:
commands:
- echo Installing dependency...
- npm install -g next
- yarn
pre_build:
commands:
- printenv > .env
build:
commands:
- echo Compiling the Node.js code
- yarn build
post_build:
commands:
- echo Build completed on `date`
artifacts:
files:
- '**/*'
最后是我的 package.json 文件;
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "next start",
"deploy": "NODE_ENV=production next build && NODE_ENV=production node ./server.js",
"analyze": "cross-env ANALYZE=true next build",
"analyze:server": "cross-env BUNDLE_ANALYZE=server next build",
"analyze:browser": "cross-env BUNDLE_ANALYZE=browser next build"
},
那个配置有什么问题。有什么想法吗?
解决方案
推荐阅读
- spring-boot - 自动装配在 flyway 回调方法中不起作用
- android - 更新图像颤振
- ios - 命令 PhaseScriptExecution 因非零退出代码 Xcode 11(BuildPhase 脚本)而失败
- php - 未捕获的 SyntaxError: missing ) 在 html 和 php 中的参数列表之后
- typo3 - Typo3 fe_user 仅获取具有特定组的用户
- jquery - 使用jquery单击复选框时无法显示/隐藏其他字段
- java - API 响应数据数组计数小于 Rest Assured Java 中的实际计数
- python - 数据集、连接、创建坐标和错误
- java - 如何将 java 项目的 maven 工件部署/托管到 Google Cloud Storage?
- javascript - 为什么我不能渲染我的`` 通过使用上标?