Skip to content

Commit

Permalink
/django-admin and /static route rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
rtrembecky committed Dec 21, 2024
1 parent b6b928c commit 55c0e2d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@ import {removeTrailingSlash} from './utils/trailingSlash'
export function middleware(req: NextRequest) {
const url = req.nextUrl

// - na deployed serveri tieto lokalne routy chyti nginx proxy a posle ich na BE,
// do tohto middlewaru sa to nedostane.
// - na localhoste tieto routy chyti next.js a posle ich do tohto middlewaru.
// simulujeme nginx podla viacmenej podla tohto:
// https://github.com/ZdruzenieSTROM/webstrom-backend/pull/491#discussion_r1893181775
if (url.pathname.startsWith('/api')) {
return backendRewriteMiddleware({req, trailingSlash: true})
}
// casopisy, riesenia, opravene riesenia
if (url.pathname.startsWith('/media')) {
return backendRewriteMiddleware({req, trailingSlash: false})
}
// napr. http://localhost:3000/django-admin
if (url.pathname.startsWith('/django-admin')) {
return backendRewriteMiddleware({req, trailingSlash: true})
}
// napr. `/django-admin` fetchuje CSSka zo `/static`
if (url.pathname.startsWith('/static')) {
return backendRewriteMiddleware({req, trailingSlash: false})
}

// https://nextjs.org/docs/app/building-your-application/routing/middleware#advanced-middleware-flags
// odstran trailing slash - default next.js spravanie, ale vypli sme ho v next.config.ts pomocou
Expand Down

0 comments on commit 55c0e2d

Please sign in to comment.