nitrojs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.build
MIT License
6.23k stars 514 forks source link

support combining vercel edge with serverless #1120

Open kikyous opened 1 year ago

kikyous commented 1 year ago

Describe the feature

Like something in next.js, user can specify runtime for a route using a named export config. I know there is a vercel-edge preset, but it is project wide.

export const config = {
  runtime: 'edge',
}

export default (req) => new Response('Hello world!')

Additional information

ugurkellecioglu commented 1 year ago

I'm facing a similar issue. I want only one of my functions to run on the edge, while the rest should be deployed as serverless. However, I couldn't find the configuration to achieve this :/

pi0 commented 1 year ago

Multi-target build to combine edge and lambda is planned: https://github.com/unjs/nitro/issues/1158

In the meantime, you can use a monorepo to build nitro app against vercel edge for that specific route and proxy from main app using route rules or directly update .vercel directory for custom handlers if really need the underlying API.

ugurkellecioglu commented 1 year ago

Thanks for the quick reply, @pi0 :) I have played with the monorepo solution a little bit. I had a Nuxt app and a Nitro app in my monorepo. When I deployed it to Vercel, both Nitro and Nuxt exported their functions into the same path (.vercel/output/functions/__nitro.func/index.mjs). Since Nitro was built first, it was just overwritten by Nuxt serverless functions. Do you have any recommendations to overcome this? Nitro app: image

Nuxt App: image

pi0 commented 1 year ago

Nice try @ugurkellecioglu! Is it possible to share your testing monorepo so i can try it?

ugurkellecioglu commented 1 year ago

@pi0 Yeah, sure: https://github.com/ugurkellecioglu/monorepo_nuxt_nitro