handle missing static folder

This commit is contained in:
Rich Harris
2019-05-10 07:38:18 -04:00
parent bedbcb834b
commit f8e853c02b

View File

@@ -6,7 +6,6 @@ import { Handler, Req, Res, MiddlewareOptions } from '../types';
import { get_server_route_handler } from './get_server_route_handler';
import { get_page_handler } from './get_page_handler';
import { lookup } from './mime';
import { stringify } from 'querystring';
export default function middleware(opts: MiddlewareOptions = {}) {
const { session, ignore } = opts;
@@ -14,7 +13,7 @@ export default function middleware(opts: MiddlewareOptions = {}) {
let emitted_basepath = false;
return compose_handlers(ignore, [
sirv('static', {
fs.existsSync('static') && sirv('static', {
dev,
setHeaders: opts.static && opts.static.headers && ((res: Response, pathname: string, stats: fs.Stats) => {
const headers = opts.static.headers(pathname, stats);