server does not connect to the right port for my DB when it makes a request

Viewed 21

I am running a node/express react app, with mongoDB as my database, its being served on a EC2 instance AWS. I am using MobaXterm to ssh into my server. The problem I am encountering, when I go to signUp/Login, and it makes the http request, its not sending the Request to port:8081 where my DB is. My front end is being hosted on port:3000, as seen here url with port. The home page of my app show display public content, but instead it shows this should display my content, instead displays html syntax. I am using PM2 to run both the front end and back end , they are 2 separate instances. Here is my ecosystem.config.js file that gets called to start the front end

module.exports = {
  apps: [
    {
      name: 'frontend',
      script: 'npx',
      args: 'serve -s build -l 3000 -n',
      interpreter: 'none',
      env: {
        NODE_ENV: 'production',
      },
    },
  ],
}

Here is my http-common.js file that sets up axios

import axios from 'axios';

const apiUrl = process.env.NODE_ENV === 'production' ? process.env.REACT_APP_PRODUCTION : process.env.REACT_APP_DEV;

export default axios.create({
  baseURL: apiUrl,
  headers: {
    "Content-type": "application/json"
  }
});

Here is where my public content on my home page is called

import http from '../http-common';
import authHeader from './auth-header';

class UserService {
  getPublicContent() {
    return http.get('api/test/all');
  };

  getUserBoard() {
    return http.get('api/test/user', { headers: authHeader() });
  };

  getModeratorBoard() {
    return http.post('api/test/mod', { headers: authHeader() });
  };

  getAdminBoard() {
    return http.put('api/test/admin', { headers: authHeader() });
  };
}

export default UserService;

and my .env.production file

REACT_APP_PRODUCTION=http://EC2-INSTANCE-URL-NOT-REAL:8081/

And you can see here that instead of the REQUEST using port:8081 it sends the request to port:3000 GET request to wrong port

**** Also my ports are open on 8081 , on the security group for the EC2 instance ***

Im new to the backend so im not sure what to do , or how to continue, I really want to have my project CI/CD working before I try to make any more progress.

0 Answers
Related