Serverless-next.js: Feature: Dynamic Route Segments Support

Created on 16 Jul 2019  ยท  4Comments  ยท  Source: serverless-nextjs/serverless-next.js

Motivation

Nextjs 9 introduced Dynamic Route segments as per this RFC.

What does this mean for this serverless plugin?

This is great news for local development when using this plugin. Currently, when you have custom page routes you can't develop / test this locally, or at least properly, since the current serverless offline support is too limited. With dynamic routes support the users should be able to just run next dev and benefit from the development experience next provides, then is the plugin's job to provide feature parity when deploying onto AWS Lambda.

Proposal

Given the following app:

pages/
โ”œโ”€โ”€ [root].js
โ”œโ”€โ”€ blog/
โ”‚ โ””โ”€โ”€ [id].js
โ”œโ”€โ”€ customers/
โ”‚ โ”œโ”€โ”€ [customer]/
โ”‚ โ”‚ โ”œโ”€โ”€ [post].js
โ”‚ โ”‚ โ”œโ”€โ”€ index.js
โ”‚ โ”‚ โ””โ”€โ”€ profile.js
โ”‚ โ”œโ”€โ”€ index.js
โ”‚ โ””โ”€โ”€ new.js
โ”œโ”€โ”€ index.js
โ””โ”€โ”€ terms.js

The plugin will automatically produce the following serverless page functions:

# [root.js]
path: /{root}
request:
  parameters:
    paths:
      root: true
# blog/[id].js
path: blog/{id}
request:
  parameters:
    paths:
      id: true
# customers/[customer]/[post].js
path: customers/{customer}/{post}.js
request:
  parameters:
    paths:
      customer: true
      post: true
# customers/[customer]/index.js
path: customers/{customer}
request:
  parameters:
    paths:
      customer: true
# customers/[customer]/profile.js
path: customers/{customer}/profile
request:
  parameters:
    paths:
      customer: true
# customers/index.js
path: customers
# customers/new.js
path: customers/new
# index.js
path: /
# terms.js
path: /terms

The option to provide custom page routes will be kept, but it is recommended you use next dynamic routes whenever possible instead.

enhancement nextjs 9.0

Most helpful comment

For next 9 support use the newly released component ๐Ÿ™ https://github.com/danielcondemarin/serverless-next.js

All 4 comments

Really interested in this. Especially if it increases DX by allowing to test our code locally the same way it runs against AWS. Env reproduction is a tough part, there are many implementations of aws lambda + next out there, but very few that have a good-enough DX for a production use case.

๐Ÿ‘

Is there a timeline on adding this support? I've been using next.js 9.0 with this plugin and all has been well, until I needed to add a dynamic route.

I'd be happy to fork and add this in if someone could give me an idea of where to look in the codebase. I'd like to get this implemented as quickly as possible.

For next 9 support use the newly released component ๐Ÿ™ https://github.com/danielcondemarin/serverless-next.js

Was this page helpful?
0 / 5 - 0 ratings