我已经使用 aws eb deploy 部署了 nodejs 应用程序,client.js 没有加载到 index.hbs 文件中并返回 404 错误(加载资源失败:服务器响应状态为 404(未找到))
我已经尝试了互联网上的所有步骤,为此浪费了两天时间。
任何人都可以在这里帮助我吗?我在这里做错了什么?
我已经在这个stackover flow page Elastic Beanstalk Static Folder 403 Error中尝试了解决方案,但没有运气
staticfiles.config (NodejsPlayGround.elasticbeanstalk\staticfiles.config) 文件
选项设置:
aws:elasticbeanstalk:container:nodejs:staticfiles:
/public: public
index.hbs (NodejsPlayGround\views\index.hbs) 文件
<!DOCTYPE html>
<html>
<head>
<title>NodeSeverTest</title>
<script src="js/client.js"></script>
</head>
<body>
<h1>Hello</h1>
</body>
</html>
server.js (NodejsPlayGround\server.js) 文件
'use strict';
const express = require('express');
const path = require('path');
const app = express();
const port = process.env.PORT || 3000;
const views_path = path.join(__dirname, 'views');
const static_path = path.join(__dirname, 'public')
app.set('view engine', 'hbs');
app.set('views', views_path);
app.get('', (req, res) => {
res.render('index', {
title: 'Weather App',
name: 'ArunKumar Arjunan'
}
);
});
app.listen(port, () => {
console.log('server started on port ' + port);
});
client.js (NodejsPlayGround\public\js\client.js) 文件:
console.log('client side java script file is loaded');
client.js 文件需要加载到 index.hbs 文件中