我使用yarn create-razzle-app my-app
. 构建后,我已将其部署到 nodeJS Elastic Beanstalk 环境中。
在点击弹性 beanstalk url 后,我看到网站没有应用任何 CSS。在本地运行相同的服务器似乎工作正常,所以我想知道是否需要做更多的工作来为弹性豆茎上的 SSR 配置 Razzle 应用程序?
检查bundle.[HASH].js
andbundle.[HASH].css
时,它们都如下所示:
<!doctype html>
<html lang="">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8" />
<title>Welcome to Razzle</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/css/bundle.9638be3a.css">
<script src="/static/js/bundle.f03ddc0c.js" defer></script>
</head>
<body>
<div id="root"></div>
</body>
</html>
这显然会导致错误,因为它不是控制台输出所指示的有效 CSS 或 JSbundle.f03ddc0c.js:1 Uncaught SyntaxError: Unexpected token '<'
index
<!doctype html>
<html lang="">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8" />
<title>Welcome to Razzle</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/css/bundle.9638be3a.css">
<script src="/static/js/bundle.f03ddc0c.js" defer></script>
</head>
<body>
<div id="root"><div class="Home"><div class="Home-header"><h2>Welcome to Razzle</h2></div></div></div>
</body>
</html>
构建时和在 Elastic Beanstalk 配置上的环境变量是:
NODE_ENV=production
PORT=8081
package.json
{
"name": "my-razzle-app",
"version": "0.1.0",
"license": "MIT",
"scripts": {
"start": "razzle start",
"build": "razzle build",
"test": "razzle test --env=jsdom",
"start:prod": "NODE_ENV=production PORT=8081 node build/server.js"
},
"dependencies": {
"express": "^4.17.1",
"razzle": "^3.0.0",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-router-dom": "^5.1.2"
}
}
.ebextensions/nodecommand.config
option_settings:
aws:elasticbeanstalk:container:nodejs:
NodeCommand: "npm run start:prod"