[점프 투 fastapi] 프론트엔드 빌드 후 문제가 발생했습니다.

Failed to load module script:
Expected a JavaScript module script but the server responded with a MIME type of "text/plain".
Strict MIME type checking is enforced for module scripts per HTML spec.

콘솔창에 위와 같은 오류가 나면서 페이지 로드가 안되는데 이유를 알 수 있을까요

bigsnim 778

2023년 4월 4일 11:29 오전

목록으로
1개의 답변이 있습니다. 1 / 1 Page

스벨트에서 빌드한 js 파일의 컨텐츠 타입이 text 인것 같아요 프론트엔드 추가 코드부분을 아래처럼 해보세요 일단 동작 됩니다

나중에 응용 센세께서 수정 해주시길..

app.mount("/assets", StaticFiles(directory="frontend/dist/assets"))

@app.middleware("http")
async def override_static_file_mimetype(request, call_next):
    if request.url.path.startswith("/assets") and request.url.path.endswith(".js"):
        response = await call_next(request)
        response.headers["content-type"] = "application/javascript"
        return response
    return await call_next(request)

@app.get("/")
async def index():
    return FileResponse("frontend/dist/index.html")

aliali

2023년 6월 14일 2:48 오전