Next.js: Add example demonstrating serverless

Created on 17 Mar 2019  路  5Comments  路  Source: vercel/next.js

Example request

Example name

example with serverless

Describe the bug

Add an example demonstrating nextjs with serverless

Additional context

Why?

The main goal is to get all the following pieces work together

  1. Use serverless
  2. Use serverless-offline to get it work for emulating locally - (development)
  3. Use express to handle all the routes and middlewares
  4. Use aws-serverless-express
  5. Deploy it on AWS lambda - (production)
good first issue example

Most helpful comment

Give me 5 minutes. I'm sending a PR 馃槃

All 5 comments

I guess https://github.com/danielcondemarin/serverless-nextjs-plugin covers what you're trying to do 馃

Give me 5 minutes. I'm sending a PR 馃槃

@timneutkens It's here 馃槈 #6685

I thought that it would be a good exercise to roll my own solution, so I have done so. My solution is a basic wrapper around the .next build folder that uses require.context that webpack makes possible to scan the .next build directory and discover all of the pages + setup express routes for them.

Now that I understand how it all works using webpack and express as ways to shortcut the solution I will be re-writing it using pure node + serverless-http. If it all works out without any major hitches I will re-upload the code as an example codebase so that people have the option of a lightweight rapper around nextjs's serverless option without having to become dependent on yet another plugin that might loose steam. That being said, holly crap there is allot of activity there currently (good sign!)

Either that or I will just replace require.context with pure node require() and that way there's no need for a build layer like webpack. I'll sleep on it and see what feels right

Closing this as we recommend using next dev in development. Deployment is easiest when using ZEIT Now as it automatically figures out static/dynamic (lambdas for dynamic, static on the CDN). https://nextjs.org/docs/deployment

Was this page helpful?
0 / 5 - 0 ratings