Commit graph

47 commits

Author SHA1 Message Date
Maia Teegarden
538095c936
Warn when response body is larger than 5mb (#26831)
This PR adds a warning when api responses exceed 5mb since this will end up failing once deployed. In a future version this scenario will throw an error.

## Bug

- [x] Integration tests added

## Documentation / Examples

- [x] Make sure the linting passes
2021-07-02 19:27:33 +00:00
Tim Neutkens
b34a0c98fa
Update err.sh links to use nextjs.org/docs/messages instead (#23353) 2021-03-29 10:25:00 +02:00
Roko Bekavac
004ad62d6b
Allow undefined body sent to sendData() (#20981)
Co-authored-by: rokobekavac0 <roko.beakavac2003@gmail.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2021-01-26 10:24:48 -05:00
Markoz Peña
6375026a41
Added Friendly error for res.redirect 🐝 (#15844)
## Which solves this PR

 Displaying a friendly error, when the user is only passing `statusOrUrl`(type number) and the second argument `url` is ignored.

**Example**

`res.redirect(307);` // Show friendly error

Closes: https://github.com/vercel/next.js/issues/15594
x-ref: https://github.com/vercel/next.js/pull/15603
2020-08-06 22:53:09 +00:00
Jonathan G
6c59cbb46a
[Feature] Progress bar for static build (#15297)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2020-08-04 09:58:23 +02:00
Ben Botvinick
d19c34353d
Add res.redirect response helper (#14705)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2020-07-07 01:06:16 -04:00
Tim Neutkens
bef9b56109
Update filename generation for client-side compilation (#14279)
Updates the way filenames are generated for browser compilation.
Notably:
- All entry bundles now have hashes in production, this includes pages (previously pages used a buildId in the path)
- The AmpFiles no longer depends on hardcoded bundle names, it uses the buildManifest instead (internals)
- All cases where we match the page name from the chunk/entrypoint name now use the same function `getRouteFromEntrypoint` (internals)
- In development we no longer include the "faked" `buildId` set to `development` for page files, instead we just use the `/_next/static/pages` path (was `/_next/static/development/pages`). This was changed as it caused unneeded complexity and makes generating the bundles easier (internals)
- Updated tons of tests to be more resilient to these changes by relying on the buildManifest instead of hardcoded paths (internals)

Follow up of these PRs:
https://github.com/vercel/next.js/pull/13759
https://github.com/vercel/next.js/pull/13870
https://github.com/vercel/next.js/pull/13937
https://github.com/vercel/next.js/pull/14130
https://github.com/vercel/next.js/pull/14176
https://github.com/vercel/next.js/pull/14268


Fixes #6303
Fixes #12087 
Fixes #1948
Fixes #4368
Fixes #4255
Fixes #2548
2020-06-20 19:59:47 +00:00
Simon Knott
a32fa4243a
Add ETag Support (#12802)
Closes #12045 

This PR adds support for [etags](https://tools.ietf.org/html/rfc7232#section-3.2) to Next.js' API routes, which will improve user experience and decrease network traffic by enabling usage of etag-based caching.
2020-05-30 19:23:24 +00:00
Joe Haddad
b7e17e09e5
Update references to zeit/next.js (#13463) 2020-05-27 17:51:11 -04:00
Joe Haddad
86160a5190
Upgrade to Prettier 2 (#13061) 2020-05-18 15:24:37 -04:00
Tim Neutkens
57dcdd90b5
Bypass OPTIONS handling for API routes (#12978) 2020-05-16 17:15:12 -04:00
Jan Potoms
32057c849d
Use the jest-circus test runner (#12974) 2020-05-16 16:56:06 -04:00
Pablo Saez
dac715e8f7
Add flag to disable API warning (#11380)
* Add flag to disable API warning

This flag is useful when you are using an external API resolver like express when defining an API route, since the native functionality doesn't realize that the API actually sent a response.

A very simple use case example https://github.com/PabloSzx/next-external-api-resolver-example

fixes #10589

* Update api-middlewares.md

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2020-05-07 14:05:41 +02:00
JJ Kasper
eeea53c04b
Fix warning for API routes with next export (#11330)
* Fix warning for API routes with next export

* Update warning copy
2020-03-24 13:38:22 -04:00
Joe Haddad
fd3256f47e
Fix Azure Pipelines (#10896)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2020-03-09 10:22:52 -04:00
JJ Kasper
178f45b2f6
Test child_process with API route (#10872) 2020-03-06 13:42:05 -05:00
JJ Kasper
65de050017
Update to not show API not ended warning when response is piped to (#10342)
* Update to not show API not ended warning when response is piped to

* Update to use res.once

Co-authored-by: Joe Haddad <timer150@gmail.com>
2020-02-02 21:48:00 -06:00
JJ Kasper
9145d9ea63
Migrate CircleCi config to GitHub actions (#10274)
* Add initial config

* Comment out other action

* Update config

* Update config

* Update configs

* rename requires -> needs

* Update configs

* Update configs

* Enable headless mode

* Disable circleci while testing

* Disable build-test-deploy in circle

* Update build step

* Disable fail fast

* Update configs

* Add runs-on to publish steps

* bump

* Update config

* Update group count

* Update checkout path

* Update test all concurrency

* Handle EPIPE errors

* Revert "Handle EPIPE errors"

This reverts commit a993565bbdd77df136e07d54eb83ed32b18e5963.

* Update test to handle EPIPE in test

* Remove CircleCi config

* Revert "Update test to handle EPIPE in test"

This reverts commit c8cb72d5303b5fd165016f9eba6c8c888d8a1907.

* Update to use node 10 and see if EPIPE error is still present

* Revert "Revert "Update test to handle EPIPE in test""

This reverts commit efd2abe7c35c12bf78530064796d853c171efcf1.

* Revert "Update to use node 10 and see if EPIPE error is still present"

This reverts commit 893da4f31279228ebec6fa208c34ef179a6ebaf4.

* Add todo for node issue

* undo lint change as it should be correct

* Add dummy step to require

* Add runs-on for dummy job
2020-01-27 14:07:31 -06:00
Matthew Sweeney
569e7acab8 Improve Stalled Requests Grammar (#10283) 2020-01-27 08:05:31 -05:00
JJ Kasper
14ca20d0d5 Add warning when API resolves without the request being finished (#9999)
* Add error when API resolves without the request being finished

* Update to only show warning in development instead

* Update packages/next/next-server/server/api-utils.ts

Co-authored-by: Joe Haddad <timer150@gmail.com>
2020-01-10 10:56:20 -05:00
Joe Haddad
00179adcaa
Fix User Error in Async API Endpoint (#9911) 2020-01-02 18:47:39 -05:00
Joe Haddad
6b50b1322b Allow Boolean API Response (#9842) 2019-12-26 15:38:12 -06:00
Joe Haddad
ec440d4b7b
Allow Empty API Body (#9838) 2019-12-26 14:23:06 -05:00
JJ Kasper
8a370d1fff
Update api-support test suite (#9673) 2019-12-09 14:17:44 -06:00
Joe Haddad
18a9c7e371
Improve linting rules to catch more errors (#9374)
* Update `packages/`

* Update examples

* Update tests

* Update bench

* Update top level files

* Fix build

* trigger
2019-11-10 19:24:53 -08:00
Jan Potoms
ab0a8647dc API: Take multiple values into account for the query (#9196)
* Take multiple values into account

* make typescript happy
2019-10-26 20:10:06 +02:00
William
ec95927e14 Fix dynamic APIs with query params (#8386)
* Fix dynamic APIs with query params

If you define a dynamic API such as

```
pages/
  api/
    [id].js
```

This api becomes available at `/api/[id]`. If you send a request with
a query parameter the value of `req.query.id` will include the query
string as well as the path parameter.

E.g. the request to `/api/2?test=123` will result in `req.query`
being

```javascript
{
  id: "2?test=123",
  test: "123",
}
```

instead of

```javascript
{
  id: "2",
  test: "123",
}
```

* Fix url parse in serverless loader

* Add serverless test
2019-08-19 13:19:39 -04:00
Luis Fernando Alvarez D
36aabe05a2 Show warning if next export detects an API route (#8257)
* Throw error if next export detects an api route

* Moved the test to the export tests

* Added missing comma

* Move the API route comment

* Add comma after replace

* Show a warning instead
2019-08-12 00:37:20 +02:00
Lukáš Huvar
869bf0f16c Remove 405 from render method (#8323)
* Revert 405 on pages

* Modify tests
2019-08-11 15:42:40 +02:00
Lukáš Huvar
abcaba7f7d
Add warning for API export (#8250) 2019-08-06 00:46:02 +02:00
Lukáš Huvar
3e03fee278 Fix build only server-side /api/index.js (#8167)
* Build error for index API routes

* Fix server build
2019-07-30 13:52:43 +01:00
Lukáš Huvar
cc6fe5fdf9 Fixes problem with API and wrong regex (#8126)
* Fixes regex for client bundel. Fixes #8115

* Add test

* Update test/integration/api-support/test/index.test.js

Co-Authored-By: Tim Neutkens <tim@timneutkens.nl>

* Update test/integration/api-support/test/index.test.js

Co-Authored-By: Tim Neutkens <tim@timneutkens.nl>
2019-07-26 17:02:12 +02:00
Lukáš Huvar
bbcb448e87 Fix index.js for API routes (#8112)
This fixes the problem with `/pages/api/index.js` not creating serverless function. Fixes #8111
2019-07-25 17:39:29 +00:00
Lukáš Huvar
3ee5ec4412 Configuration for body parsing size limit (#7896)
This PR introduces the possibility to change the size of the parsed body. This brings features like:
- Adjusting the size of the incoming message
- Better security
2019-07-25 15:43:55 +00:00
Joe Haddad
aac5121466
Apply missing formatting (#8079)
* Reapply missing formatting

* Fix lint
2019-07-23 14:33:49 -04:00
Lukáš Huvar
fce7e4eaee Avoid sending user errors to client (#8005)
* Avoid sending user error to client Closes #7526

* Small improvments

* Update sending errors
2019-07-16 17:35:13 -07:00
Lukáš Huvar
718a36e127 Fix build for API routes conflict pages (#7992)
* Fixes #7991

* Fix tests
2019-07-16 12:59:09 +02:00
JJ Kasper
66a03bf1ff Add test for trailing slash on API route (#7851) 2019-07-09 16:34:12 -04:00
Lukáš Huvar
f204935251 Fix serverless loader for API routes (#7767)
* Fix serverless loader for API routes

* Only use params with dynamic routes
2019-07-07 17:45:40 -04:00
Lukáš Huvar
87acbdb594
Http methods update for static files and pages (#7721)
* Change static method handling and pages revert

* Allow and reflect old behaviour

* Post should return 501

* Add back old test

* Invert logic

* Handle 501 for pages in separate location

* Remove usage of 501 HTTP status code

* Prevent information leak

* Add test

* Only 405 if the page exists -- 404 if it doesn't

* Handle sent responses

* Revert "Handle sent responses"

This reverts commit 5e9012ae29b611c25ed1e090756a25dbe3437182.

* Fix bad test

* Switch back to quiet

* Update test/integration/production/test/index.test.js

Co-Authored-By: JJ Kasper <jj@jjsweb.site>
2019-07-04 10:22:25 +02:00
Lukáš Huvar
4ad934c148 Serverless build for API routes (#7649)
* Fixes serverless target in development

* Fix serverless build

* Fix serverless build

* Add manifest test

* Better output

* Fix manifest test

* Update snapshot

* Remove snapshots
2019-07-01 12:47:11 -04:00
Lukáš Huvar
c156e0c889
Helpers update (#7686)
* Update helper function to invoke only on get

* Tests for body parsing

* Update api-utils.ts

* Update next-server.ts

* Update packages/next-server/server/next-server.ts

Co-Authored-By: JJ Kasper <jj@jjsweb.site>
2019-06-28 11:31:32 +02:00
Lukáš Huvar
bd31c5d1b7 Dynamic routes for API (#7629)
* Dynamic routes for API

* New structure

* Change next config

* Refactoring tests

* Fix newline

* Fix tests

* Remove dynamic from config

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <timer150@gmail.com>

* Update index.test.js
2019-06-27 12:01:36 -04:00
Lukáš Huvar
ff040950eb Fixes serverless target in development (#7619) 2019-06-20 19:47:45 -07:00
Lukáš Huvar
c821e83048 API interface extensions (#7363)
* Cookies and Query parsing for API request

* Adding JSON and SEND

* First body parsing

* Body parsing

* Remove extra try catch

* Fix tests

* Only server bundling for API routes

* Update packages/next-server/server/api-utils.ts

Co-Authored-By: Tim Neutkens <tim@timneutkens.nl>

* Revert on demand server changes

* Use content-type for parsing

* Update packages/next-server/server/api-utils.ts

Co-Authored-By: Jan Potoms <potoms.jan@gmail.com>

* Add tests for server compilation

* Add body limit

* Change API to function chaining

* Limit test
2019-06-05 13:22:09 +02:00
Lukáš Huvar
b5e3aac1ec Fix POST and PUT on api routes (#7319)
* Fix POST and PUT

* Fix condition for request and test
2019-05-13 15:40:23 +02:00
Lukáš Huvar
fedfbd9d5c Experimental API support (#7296)
* First basic API support

* Change require functionality

* Change 501 to 404

* Change wording

* Fix test
2019-05-11 13:18:56 +02:00