Skip to content

Releases: adonisjs/http-server

Add support for lazy importing middleware

13 Feb 05:31
Compare
Choose a tag to compare

This release attempts to improve the intellisense of Typescript now and also in the future. Moving forward, we will recommend registering middleware as follows:

Server.middleware.register([
  () => import('@ioc:Adonis/Core/BodyParserMiddleware'),
  () => import('App/Middleware/Auth')
])
  • feat: allow lazy imports when registering middleware b3e22a0
  • refactor: update code to use latest APIs of the IoC container ec1327e
  • chore: use cuid from poppinss 98ca254

v5.0.1...v5.1.0

Remove Route.forTesting method

12 Feb 10:08
Compare
Choose a tag to compare

The method was added to test middleware or validator by creating a test only route. However, removing the route is not possible coz of the internal data structure of the routes store and hence these routes will start conflicting.

There are better ways to best middleware or validator in isolation and docs will shed some light on it

Commits

  • refactor: remove Route.forTesting 31f73c7
  • refactor: request.toJSON now also includes subdomains, ip and hostname ee762fd
  • feat: accept array in response.vary method 91d7e10

v5.0.0...v5.0.1

New features and some breaking changes

12 Feb 09:52
Compare
Choose a tag to compare

Breaking changes

Following is the list of breaking changes. The transition from preview to the main version is our best bet to come up with all the breaking changes

route.makeUrl

The route.makeUrl was overloaded with too many options. We tried improving the API and also introduce a new URL builder API.

For the most common use case, there are no breaking changes. But a few, if you are generating URLs for a specific domain

Following examples will continue to work

// Will continue to work
Route.makeUrl('PostsController.show', { id: 1 })
Route.makeUrl('PostsController.show', {
  id: 1,
  qs: { published: true }
})

// Will continue to work
Route.makeUrl('PostsController.show', { params: { id: 1 } })
Route.makeUrl('PostsController.show', {
  params: { id: 1 },
  qs: { published: true }
})

Following will not work

Route.makeUrl(
  'PostsController.show',
  { id: 1 },
- 'blog.adonisjs.com'
)

Route.makeUrl(
  'PostsController.show',
  { id: 1 },
+ {
+  domain: 'blog.adonisjs.com'
+ })

Also prefixDomain and domainParams have been removed and you should instead use the prefixUrl option. Following is the new ideal API

// Pass params as an array
Route.makeUrl('/posts/:id', [1])

// Pass params as an object
Route.makeUrl('/posts/:id', { id: 1 })

// Options as 3rd argument
Route.makeUrl(
  '/posts/:id',
  { id: 1 },
  { qs: { published: true } }
)

Route.makeSignedUrl

The same changes are made to the makeSignedUrl method as well

Deprecate

The request.get and request.post methods have been deprecated in favor of request.qs and request.body. They were badly named at the first place.

- request.get()
+ request.qs()

- request.post()
+ request.body()

New features

Route param cast function

Along side the route matchers, you can also define a function to cast the parameter value. For example:

Route
  .get('users/:id', 'UsersController.show')
  .where('id', {
    match: /^[0-9]+$/,
    cast: (id) => Number(id)
  })

In the above example, the cast method converts the string representation of the number to an actual Number. We also ship with a couple of commonly use matchers too

Route
  .get('users/:id', 'UsersController.show')
-  .where('id', {
-    match: /^[0-9]+$/,
-    cast: (id) => Number(id)
-  })
+  .where('id', Route.matchers.number())

Add route.redirect method

Along side the route.render method, we now also have shortcut methods to redirect the request.

Route.get('guides/:doc', 'GuidesController.show')
Route.on('docs/:doc').redirect('GuidesController.show')

To redirect to an exact URL, you can make use of the redirectToPath method.

Route.on('blog/:slug').redirectToPath('https://medium.com/my-blog')

Commits

Check the following commits for bug fixes

  • chore(deps): bump ini from 1.3.5 to 1.3.8 (#36) fa09eea
  • feat: add brisk route redirect methods 2af36d6
  • fix: remove etag when streaming response fails 5a362f6
  • fix: response.send now sends 304 status code when etag cache is fresh 4668dfd
  • refactor: change signature of response.abortUnless 6ab60ee
  • refactor: the API for making urls from routes 5c7e39c
  • test: write test for an edge case param matcher test ac2480a
  • feat: add shortcut methods for defining route param matchers 29dd0d0
  • feat: add support for defining route casters 3324daf
  • improvement: deprecate request.get and request.post in favor of request.qs and request.body c40bbe3
  • fix: response.redirect forward referrer query string 6d716c1
  • style: reformat source files 94df36a
  • chore: remove npm-audit in favor of synk a06d736
  • chore: update dependencies b4c8bc8
  • fix(router): adding support for HEAD HTTP method for all GET routes back to v5 (#32) 05c00a2
  • fix: upgrade ms from 2.1.2 to 2.1.3 (#29) ea55c2a
  • chore(deps): bump ini from 1.3.5 to 1.3.8 (#28) 396a353
  • chore(deps): bump highlight.js from 10.4.0 to 10.4.1 (#26) c78cf09

v4.0.9...v5.0.0

Fix bug for 304 status code crashing the server when body was defined

24 Nov 19:07
Compare
Choose a tag to compare
  • chore: stale config ignore label 'Status: Blocked' 5c4c7c0
  • fix: type errors 1f0a4e0
  • fix: ignore body when status code is 304 e2dac20
  • chore: update dependencies 08ba940
  • chore(deps): bump find-my-way from 3.0.4 to 3.0.5 (#24) 29706c2

v4.0.8...v4.0.9

Publish under latest tag

24 Oct 12:04
Compare
Choose a tag to compare
  • chore: use latest tag for publishing to npm 66b6de8
  • refactor: add body and params to request.toJSON output fc76878
  • chore: update dependencies 1fb9e90

v4.0.7...v4.0.8

Revert v4.0.6

20 Oct 16:47
Compare
Choose a tag to compare
  • revert: feat: add request.inertia to know if request has inertia header 7fa65d9

v4.0.6...v4.0.7

Add request.inertia method to check for X-Inertia header

20 Oct 15:57
Compare
Choose a tag to compare
  • feat: add request.inertia to know if request has inertia header 4fe885d
  • chore: update dependencies d793b20

v4.0.5...v4.0.6

Fix issue around sending undefined body with explicit status code

13 Oct 05:06
Compare
Choose a tag to compare
  • fix: do not crash when body is undefined and explicit status code is defined 40a2ff3
  • chore: update dependencies f79fdfe

v4.0.4...v4.0.5

Update underlying dependencies

10 Oct 05:16
Compare
Choose a tag to compare

Upgrade dependencies

01 Oct 14:22
Compare
Choose a tag to compare
  • test: fix breaking tests after dependencies upgrade 66ecc1c
  • chore: update dependencies 264e056
  • refactor: validate server config 5dfc37d

v4.0.2...v4.0.3