-
Notifications
You must be signed in to change notification settings - Fork 78
feat: add internal server for serverMiddleware #375
Conversation
…me deployment as Nuxt
There is no step 4 now
|
@dtinth great idea - but would you make it opt-in rather than on by default, as I imagine it has a performance cost to cold start? (I'd also appreciate it if you could do some perf benchmarks) |
|
@danielroe I strongly doubt that there would be any, if at all, performance hit in cold start.
|
* if there is serverMiddleware in `nuxt.config` * if it is enabled in package config
|
Thanks @danielroe! |
|
This is awesome, was literally just wishing I could use serverMiddleware this way an hour or two after @dtinth forked this, and then bam it's merged in! You guys rock. |
|
I'm just going to throw this out there for anyone, like me, who is struggling to get an express API running at all, and can NOT figure out why it works locally but not in Vercel. Make sure express is in your dependencies and not your devDependencies! |
|
I am lost, what's the solution? I already have a project ready on deployment and when I deploy it to vercel it fails 😅 and I still don't know what to do |
Running Nuxt and API on the same server is a common use case.
At first, this is not supported. Quoting @danielroe from #332 (comment):
Later in #341, it was suggested that using
$VERCEL_URLcan work around this issue. I previously filed #373 which adds a docs about this workaround. Although it works, it is quite hacky and is unperformant:$VERCEL_URLto be able to make Nuxt invoke the API on the same deployment.Today, I took a quick look at the source code and I discovered a simple fix: Just launch an HTTP server on port 3000 (this happens to be the default port configured by
@nuxtjs/axios) and problem is solved. Using@nuxtjs/axiosto call serverMiddleware API on server side “just works” now.How to try it out
I published my fork to
npmso you can"use": "@dtinth/nuxtjs__vercel-builder@prerelease"to test it.