Cannot GET from Express server in production, 404 (Not Found)
See original GitHub issueHi,
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:
- Created 3 years ago
- Comments:10
Top GitHub Comments
@JonathanWexler If you are using
create-nuxt-app
, you will notice the start command in the package.json is notnuxt start
and it have been replaced bycross-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. Runnpm run start
oryarn start
instead.@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
andProcfile
if you needed.