I can appreciate that this is quite a specific question, but I could really use some help because I am stuck for why this could be occurring.
I followed this Tutorial to upload my React / Express / Node app to AWS EC2.
You can see the Project Structure on Github. My server is in a different folder, but this shouldn't make a difference. Link to Github:
The front end works fine, and you can view it here.
It's the 'contact me' section at the bottom that I need to get to work. It links up with Nodemailer on the back-end to send me an email to my gmail.
Works fine in a development environment.
When I hit the api endpoint http://3.138.194.248/api/send with postman, I get back a message:
{
"success": false,
"message": "Something went wrong. Try again later"
}
Which I have set, so it would appear that the Express app is actually running.
I'm using pm2 and NGINX.
Environment variables are set up in a .env file in Ubuntu, exactly as they were in my development environment.
My NGINX config is as such
server {
listen 80;
location / {
proxy_pass http://{{PRIVATE IP FROM EC2 INSTANCE}}:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Express app looks like so:
const path = require('path');
const cors = require('cors');
const express = require('express');
const app = express();
const buildPath = path.join(__dirname, '..', 'client/dist');
app.use(express.json());
app.use(express.static(buildPath));
app.use(cors());
const routes = require('./routes/api');
const port = process.env.PORT || 5000
app.listen(port, () => {
console.log(`server start on port ${port}`);
})
app.use('/api', routes);
This seems to be giving me a 500 error in the console and it's not working anyhow.
Does anyone have some good troubleshooting steps that I can try or perhaps know why this might be happening?