feat(#27): Set up consola logger, make use of log levels in backend and frontend
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
import type { H3Event } from 'h3'
|
||||
import { joinURL } from 'ufo'
|
||||
import { jwtDecode } from 'jwt-decode'
|
||||
import { createLogger } from '~~/shared/utils/logger'
|
||||
|
||||
export default defineEventHandler(async (event: H3Event) => {
|
||||
const { serverApiBaseUrl, clientProxyBasePath } = useRuntimeConfig().public
|
||||
const logger = createLogger({
|
||||
level: useRuntimeConfig().public.logLevel,
|
||||
tag: '🔀 proxy'
|
||||
})
|
||||
const escapedClientProxyBasePath = clientProxyBasePath.replace(/^\//, '\\/')
|
||||
// Use the escaped value in the regex
|
||||
const path = event.path.replace(new RegExp(`^${escapedClientProxyBasePath}`), '')
|
||||
@@ -19,8 +24,10 @@ export default defineEventHandler(async (event: H3Event) => {
|
||||
})
|
||||
}
|
||||
|
||||
if (accessToken) console.log('🔀 [PROXY] Expiration:', new Date(jwtDecode(accessToken).exp! * 1000).toISOString())
|
||||
console.log('🔀 [PROXY] Proxying request to:', target)
|
||||
if (accessToken) {
|
||||
logger.debug('Expiration:', new Date(jwtDecode(accessToken).exp! * 1000).toISOString())
|
||||
}
|
||||
logger.debug('Proxying request to:', target)
|
||||
|
||||
return proxyRequest(event, target, {
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user