You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a custom middleware (in my scenario for auth purposes) in the ~/server folder, managementUI breaks. It seems like the content type is not set correctly, causing pages to show plain text instead of HTML and etc.
To reproduce just place any middleware in server, like for example:
Bad Workaround in my scenario looks like this (seriously, don't do this):
import{getServerSession}from"#auth"exportdefaultdefineEventHandler(async(event)=>{consturl=getRequestURL(event)if(!url.pathname.startsWith('/_concierge'))returnconstauth=awaitgetServerSession(event)if(!auth){returnsendRedirect(event,'/auth/signin?callbackUrl='+encodeURIComponent(url.pathname+url.search))}// set appropriate headers for files, since it is broken by middleware// TODO: remove this hackconstcontentMap={'css': 'text/css','js': 'text/javascript','html': 'text/html','json': 'application/json','svg': 'image/svg+xml',}if(url.pathname.startsWith('/_concierge/api')){setResponseHeaders(event,{'Content-Type': 'application/json',})}else{consttype=url.pathname.split('.').pop()||'html'constcustomContentType=contentMap[typeaskeyoftypeofcontentMap]||'text/html'setResponseHeaders(event,{'Content-Type': customContentType,})}})
The text was updated successfully, but these errors were encountered:
0x77dev
changed the title
When using server middlewares content type disappears
When using server middlewares content type disappears inside managementUI
Mar 25, 2024
When using a custom middleware (in my scenario for auth purposes) in the
~/server
folder,managementUI
breaks. It seems like the content type is not set correctly, causing pages to show plain text instead of HTML and etc.To reproduce just place any middleware in server, like for example:
Bad Workaround in my scenario looks like this (seriously, don't do this):
The text was updated successfully, but these errors were encountered: