axios + vercel + servermiddleware issue
See original GitHub issuehi,
there is no way i can find a good solution to make the api url work well.
my vercel.json
: https://github.com/nuxt/now-builder/blob/master/examples/basic/now.json
my nuxt.config.js
:
export default {
serverMiddleware: [
{
path: '/api/test',
handler: '~/server-middleware/test.js'
}
]
}
my /server-middleware/test.js
:
const json = JSON.stringify({
status: 'hello'
})
export default (req, res) => {
res.writeHead(200, {'Content-Type': 'application/json'}).end(json)
}
my /pages/index.vue
:
<template>
<div>
<p v-if="$fetchState.pending">Fetching posts...</p>
<p v-else-if="$fetchState.error">Error while fetching posts: {{ $fetchState.error.message }}</p>
<h1>Works! {{ status }}</h1>
</div>
</template>
<script>
export default {
async fetch () {
this.status = await this.$axios.$get('/api/test')
},
data () {
return {
status: {}
}
}
}
</script>
after deploy, you always want to get it at http://127.0.0.1/api/test.
how can i specify that the vercel url be the api url?
what is the good solution for this?
i tried process.env.VERCEL_URL
too but it didn’t work.
of course api is good in local environment, it works.
thanks for the help
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
axios + vercel + servermiddleware issue #290 - GitHub
hi, there is no way i can find a good solution to make the api url work well. my vercel.json: ...
Read more >ERROR 500 on axios API Call in Next JS after deployment to ...
SOLUTION: I looked into the Vercel functions logs and got an error for the handlebars template file. File not found.
Read more >cannot set headers after they are sent to the client axios
I have an issue where if i reload the page im standing on in my nuxt app it redirects me to the login...
Read more >dtinth/nuxtjs__vercel-builder NPM
A common use case in Nuxt is to use serverMiddleware put an API server on the same server as Nuxt. ... Set up...
Read more >API Routes: Request Helpers - Next.js
API Routes provide built-in request helpers that parse the incoming request. Learn more about them here.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can easily setup with these config :
then simply
Hopefully this explanation might be helpful.
@kukac7 System environment variables work just fine.