2

I have deployed the nodejs application with aws eb deploy, client.js is not getting loaded in index.hbs files and returning 404 error (Failed to load resource: the server responded with a status of 404 (Not Found))

I have tried all the step in the internet and wasted two days for this.

Can any one please help me here ? I am doing anything wrong here?

I have tried the solution in this stackover flow page Elastic Beanstalk Static Folder 403 Error but no luck

staticfiles.config(NodejsPlayGround.elasticbeanstalk\staticfiles.config) file

option_settings:

aws:elasticbeanstalk:container:nodejs:staticfiles:
/public: public

index.hbs(NodejsPlayGround\views\index.hbs) file

<!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) file

'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) file:

console.log('client side java script file is loaded');

client.js file needs to be loaded in index.hbs file

1 Answers1

0

I find that contrary to the AWS documentation on this, the folder path also needs a leading slash — i.e. you map /public to /public (not just public), or /static to /static (not just static).

I figured this out by inspecting the nginx error log and conf files on my EB instances, and both showed that it was looking for my static files in /var/app/currentstatic instead of /var/app/current/static.

jawj
  • 463
  • 3
  • 11