Skip to content
This repository has been archived by the owner on Jan 28, 2025. It is now read-only.

feat(core, nextjs-component): improve routing and support cross rewrites for consolidated API pages in default lambda #1693

Merged
merged 2 commits into from
Sep 15, 2021

Conversation

dphang
Copy link
Collaborator

@dphang dphang commented Sep 15, 2021

  • experimental: set build.separateApiLambda = false to enable single lambda for pages + APIs
  • moves API page routing/rendering to default handler routing, which is cleaner as it already provides abstractions over different route types. It's easier also to add logic in page manifest parsing to treat API pages as another page type, so it lives with the regular HTML/SSG/SSR pages. We can get rewrite logic mostly for free.
  • cross rewrites like /page <-> /api/page should now work (there is a simple e2e test added for the basic cases).
  • we will also get nice 404 pages instead of the previous text-only, uncustomizable 404 page for APIs.
  • this is mainly only tested in e2e next-app-experimental. But if this becomes the default later, we will need to update unit tests

Fixes: #939

@dphang dphang changed the title feat(core, nexts-component): improve routing and support cross rewrites for consolidated API pages in default lambda feat(core, nextjs-component): improve routing and support cross rewrites for consolidated API pages in default lambda Sep 15, 2021
@slsnextbot
Copy link
Collaborator

slsnextbot commented Sep 15, 2021

Handler Size Report

There are changes to handler sizes. Please review.

Base Handler Sizes (kB) (commit c5859c7)

{
    "Lambda@Edge": {
        "Default Lambda": {
            "Standard": 1271,
            "Minified": 453
        },
        "API Lambda": {
            "Standard": 100,
            "Minified": 44
        },
        "Image Lambda": {
            "Standard": 933,
            "Minified": 371
        },
        "Regeneration Lambda": {
            "Standard": 655,
            "Minified": 237
        }
    }
}

New Handler Sizes (kB) (commit 4a651f5)

{
    "Lambda@Edge": {
        "Default Lambda": {
            "Standard": 1268,
            "Minified": 452
        },
        "API Lambda": {
            "Standard": 101,
            "Minified": 44
        },
        "Image Lambda": {
            "Standard": 933,
            "Minified": 371
        },
        "Regeneration Lambda": {
            "Standard": 655,
            "Minified": 237
        }
    }
}

@codecov
Copy link

codecov bot commented Sep 15, 2021

Codecov Report

Merging #1693 (4a651f5) into master (c5859c7) will increase coverage by 0.08%.
The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1693      +/-   ##
==========================================
+ Coverage   83.86%   83.95%   +0.08%     
==========================================
  Files          98       98              
  Lines        3477     3477              
  Branches     1045     1045              
==========================================
+ Hits         2916     2919       +3     
+ Misses        499      496       -3     
  Partials       62       62              
Impacted Files Coverage Δ
packages/libs/lambda-at-edge/src/build.ts 96.28% <ø> (ø)
...ackages/libs/lambda-at-edge/src/default-handler.ts 88.88% <ø> (+2.85%) ⬆️
packages/libs/core/src/handle/default.ts 85.71% <33.33%> (-10.84%) ⬇️
packages/libs/core/src/route/page.ts 95.65% <71.42%> (-4.35%) ⬇️
packages/libs/core/src/build/index.ts 95.45% <100.00%> (+0.16%) ⬆️
packages/libs/core/src/build/ssr.ts 100.00% <100.00%> (ø)
...rless-components/nextjs-component/src/component.ts 86.28% <100.00%> (+0.82%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5859c7...4a651f5. Read the comment docs.

@dphang dphang marked this pull request as ready for review September 15, 2021 17:59
@dphang dphang merged commit f058d51 into master Sep 15, 2021
@delete-merged-branch delete-merged-branch bot deleted the dphang/cross-rewrites branch September 15, 2021 18:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrites to /api paths are resulting in 404
2 participants