Repository navigation
This update includes a range of improvements, new features, and bug fixes to enhance the overall development experience. Below is a summary of the key changes:
π New Features
- Middleware Matcher Support:
Added the ability to pass a custom matcher to middleware. You can now use:- A path-to-regexp string matcher.
- A regular expression.
This makes it easier to specify which routes the middleware applies to, offering more flexibility and control.
// middleware.ts
import { NextUse } from 'midnext'
export async function middleware(request: Request, event: Event) {
return new NextUse({ request, event })
.use((req, res) => {
...
})
.use(/.*/, async (req, res, event) => {
...
})
.use('/abs', async (req, res, event) => {
...
})
.run()
}
export const config = {}π Bug Fixes
- Cookie Issue with Redirects:
Fixed an issue where cookies were not being sent along with redirects. Now all cookies are properly transmitted during redirects, ensuring smoother and more consistent session handling.
// middleware.ts
import { NextUse } from 'midnext'
export async function middleware(request: Request) {
res.cookies.set('my-cookie', 'abc')
return new NextUse({ request })
.use((req, res) => {
return res.redirect('http://example.com', {
headers: res.headers, // Attach headers to the redirect response
status: 302
})
})
.run()
}
export const config = {}