question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot GET from Express server in production, 404 (Not Found)

See original GitHub issue

Hi,

I’m attempting to deploy a Nuxt app with an express server. I have tried deploying to both Heroku and Netlify and have gotten the same error on both, so I’m assuming there’s an error somewhere in my Nuxt/Express configuration. I created a new test app to see if I could resolve the issue and even that is giving me issues.

Everything works fine locally, but when deployed, returns a 404 error.

To Reproduce

npx create-nuxt-app testapp
? Project name testapp
? Project description My smashing Nuxt.js project
? Author name Mike
? Choose programming language JavaScript
? Choose the package manager Npm
? Choose UI framework None
? Choose custom server framework Express
? Choose Nuxt.js modules Axios
? Choose linting tools None
? Choose test framework None
? Choose rendering mode Universal (SSR)
? Choose development tools jsconfig.json (Recommended for VS Code)

cd testapp and npm run dev

I added a simple button to log the result of GETting from my test endpoint to pages/index.vue

<template>
  <section class="container">
    <button @click="logTest">Log Test</button>
  </section>
</template>

<script>
import axios from 'axios'
export default {
  methods: {
    logTest() {
      return axios.get('/test').then((res) => {
        console.log('got data:', res.data)
      })
    }
  }
}
</script>

and added the following test endpoint in server/index.js right above app.use(nuxt.render)

 app.get('/test', (req, res) => {
    res.status(200).send('reached test endpoint')
  })

This works fine locally, when I click the button, I see ‘got data: reached test endpoint’ in my console. Once deployed to heroku, in the console, I get

GET https://TESTAPPURL.herokuapp.com/test 404 (Not Found)
Error: Request failed with status code 404
    at t.exports (f31d605....js:2)
    at t.exports (f31d605....js:2)
    at XMLHttpRequest._.onreadystatechange (f31d605....js:2)

To deploy to heroku, I have followed the instructions here

Thanks in advance, I’d appreciate any help as I’ve been stuck on this for several days now. Not sure if this is a bug or just something wrong with my configuration, just doesn’t make sense as I haven’t changed any setup from the default scaffolding and it works locally.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

2reactions
climba03003commented, May 12, 2020

@JonathanWexler If you are using create-nuxt-app, you will notice the start command in the package.json is not nuxt start and it have been replaced by cross-env NODE_ENV=production node server/index.js.

As my first comment, nuxt start is using the nuxt server. Which will not respect any code in your modified server. Run npm run start or yarn start instead.

2reactions
climba03003commented, May 12, 2020

@mikeglopez I have created a test application at heroku which works perfectly fine. ( Note: It will be removed within one or two weeks )

Remove the Procfile file because it is not really needed. start command in package.json will be run by heroku automatically.

You may also access the gist for package.json and Procfile if you needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express Server - GET request returns a 404 (Not Found)
I've searched online and cannot find a solution to my problem, to me the GET request looks right, maybe I've not set my...
Read more >
Why am I receiving a 404 not found when I try to access a ...
I am using nodejs. When I try to access a route other than “/”, I receive 404 not found. It works https://www.celr.com.br.
Read more >
FAQ - Express.js
In Express, 404 responses are not the result of an error, so the error-handler middleware will not capture them. This behavior is because...
Read more >
Node.js Error: Cannot GET/ from running the url on the web ...
Reason: Since in the server file, we create a get route for '/messages' URL but inside the browser, we try to get the...
Read more >
Express/Node introduction - Learn web development | MDN
You can use Node.js to create a simple web server using the Node ... If a file cannot be found by one middleware...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found