This error occurs when I try to access to the root path ("/") of my MERN application. Though accessing to this path on local machine works fine and I get React application. React app uses 3000 port but server uses 8080. I built my app using this boilerplate: https://github.com/crsandeep/simple-react-full-stack/ (just changing files in "client", "server" and "public" directories and changing paths to client in "webpack.config.js")
I also tried to cover the main component of my app with router (in "index.js" of client) like this:
<Router>
<Route exact path="/" component={MessageBoard} />
</Router>
But I still get the error. What is the issue?
UPD: Contents of server.js is :
const express = require("express");
const logger = require("morgan");
const API_PORT = process.env.PORT || 8080;
const app = express();
const router = require('./routers/board');
app.use(logger("dev"));
app.use('/api', router);
app.listen(API_PORT, () => {
console.log(`LISTENING ON PORT ${API_PORT}`)
});
UPD 1: Contents of "/etc/nginx/sites-available/default":
server {
listen 80;
server_name ec2-18-222-203-253.us-east-2.compute.amazonaws.com www.ec2-18-222-203-253.us-east-2$
location / {
proxy_pass http://127.0.0.1:8080;
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;
proxy_redirect off;
}
}
It looks like your app doesn't listen to the '/' path...
The only path you listen is the '/api' and use the router.
If you would like to get '/', try to listen '/'
app.get('/',(req,res)=>{
//do something
});
or, I noticed in your rep, there is a app.use(express.static('dist'));
, maybe you should check the path to the "dist" if your react app or something is in the 'dist' folder.
There is a NGnix server in front of your app. This server is not correctly configured, it can not access your app. The problem is in the configuration of NGinx, not in your app.
HTTP 404 means NOT_FOUND
. This error is returned by NGinx, not your app.
$ curl -v http://ec2-18-222-203-253.us-east-2.compute.amazonaws.com/
* Trying 18.222.203.253...
* TCP_NODELAY set
* Connected to ec2-18-222-203-253.us-east-2.compute.amazonaws.com (18.222.203.253) port 80 (#0)
> GET / HTTP/1.1
> Host: ec2-18-222-203-253.us-east-2.compute.amazonaws.com
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Server: nginx/1.10.3 (Ubuntu)
< Date: Tue, 12 Mar 2019 10:21:21 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 139
< Connection: keep-alive
< X-Powered-By: Express
< Content-Security-Policy: default-src 'self'
< X-Content-Type-Options: nosniff
<
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /</pre>
</body>
</html>
* Connection #0 to host ec2-18-222-203-253.us-east-2.compute.amazonaws.com left intact
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With