import { Application , static as staticServer } from "express" ; import index from "serve-index" ; import { getLogger } from "@cocalc/project/logger" ; export default function init ( app , base ) { const winston = getLogger ( "serve-static-files-to-browser" ) ; winston . info ( `initialize with base="${ base }"` ) ; app . use ( base , ( req , res , next ) => { if ( req . query . download != null ) { res . setHeader ( "Content-Type" , "application/octet-stream" ) ; } res . setHeader ( "Cache-Control" , "private, must-revalidate" ) ; next ( ) ; } ) ; const { HOME } = process . env ; if ( HOME == null ) { throw Error ( "HOME env variable must be defined" ) ; } winston . info ( `serving up HOME="${ HOME }"` ) ; app . use ( base , index ( HOME , { hidden : true , icons : true } ) ) ; app . use ( base , staticServer ( HOME , { dotfiles : "allow" } ) ) ; }