Skip to content

Commit

Permalink
chore: add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Feb 9, 2024
1 parent ffe5856 commit ea30dad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cypress/e2e/middleware/standard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ describe('Standard middleware', () => {
cy.url().should('eq', `${Cypress.config().baseUrl}/shows/rewrite-external`)
})

it('doesnt follow redirects from rewritten page', () => {
cy.request({ url: '/rewrite-to-redirect', followRedirect: false }).then((response) => {
expect(response.status).to.eq(302)
expect(response.redirectedToUrl).to.eq('https://example.com')
})
})

it('adds headers to static pages', () => {
cy.request('/shows/static/3').then((response) => {
expect(response.headers).to.have.property('x-middleware-date')
Expand Down
4 changes: 4 additions & 0 deletions demos/middleware/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export async function middleware(req: NextRequest) {
return res
}

if (pathname.startsWith("/rewrite-to-redirect")) {
return NextResponse.rewrite('https://httpbin.org/redirect-to?url=https://example.com')
}

// skipMiddlewareUrlNormalize next config option is used so we have to try to match both html path and data blob path
if (pathname.startsWith('/request-rewrite') || pathname.endsWith('/request-rewrite.json')) {
// request.rewrite() should return the MiddlewareResponse object instead of the Response object.
Expand Down

0 comments on commit ea30dad

Please sign in to comment.