Skip to content

Commit

Permalink
#1129 More traces
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Dec 1, 2023
1 parent 2863c07 commit 4cfdca4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions ontrack-web-core/.env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# NEXT_PUBLIC_LOCAL=true
NEXT_PUBLIC_ONTRACK_CONNECTION_LOGGING=true
NEXT_PUBLIC_ONTRACK_CONNECTION_TRACING=true
NEXT_PUBLIC_ONTRACK_URL=http://localhost:8080
NEXT_PUBLIC_ONTRACK_UI_URL=http://localhost:3000/ui
4 changes: 4 additions & 0 deletions ontrack-web-core/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ export const ontrackUiUrl = () => {
export const isConnectionLoggingEnabled = () => {
return process.env.NEXT_PUBLIC_ONTRACK_CONNECTION_LOGGING === 'true'
}

export const isConnectionTracingEnabled = () => {
return process.env.NEXT_PUBLIC_ONTRACK_CONNECTION_TRACING === 'true'
}
27 changes: 12 additions & 15 deletions ontrack-web-core/middleware.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
import {NextResponse} from "next/server";
import {cookieName, cookieOptions, isConnectionLoggingEnabled, ontrackUiUrl, ontrackUrl} from "@/connection";

// export const config = {
// matcher: [
// /*
// * Match all request paths except for the ones starting with:
// * - _next/static (static files)
// * - _next/image (image optimization files)
// * - favicon.ico (favicon file)
// * - ontrack_ (logo)
// */
// '/((?!api|_next/static|_next/image|favicon.ico|ontrack_).*)',
// ],
// }
import {
cookieName,
cookieOptions,
isConnectionLoggingEnabled,
isConnectionTracingEnabled,
ontrackUiUrl,
ontrackUrl
} from "@/connection";

export default function middleware(request) {

const logging = isConnectionLoggingEnabled()
const tracing = logging && isConnectionTracingEnabled()
const path = request.nextUrl.pathname
// if (logging) console.log(`[connection][middleware][${path}] Path received`)

if (
!path.startsWith('/_next') &&
!path.startsWith("/ontrack") &&
!path.startsWith("/api") &&
!path.startsWith("/favicon")
) {
if (logging) console.log(`[connection][middleware][${path}] CHECKING`)
const cookie = request.cookies.get(cookieName)
if (cookie) {
if (logging) console.log(`[connection][middleware][${path}] Cookie is already set`)
Expand Down Expand Up @@ -57,5 +52,7 @@ export default function middleware(request) {
return NextResponse.redirect(new URL(url))
}
}
} else if (tracing) {
console.log(`[connection][middleware][${path}] PASSTHROUGH`)
}
}

0 comments on commit 4cfdca4

Please sign in to comment.