UNPKG

@zkochan/pnpm

Version:

A fast implementation of npm install

34 lines (29 loc) 907 B
/** * Copyright 2015 Google Inc. All Rights Reserved. * Use of this source code is governed by a BSD-style * license that can be found in the LICENSE file or at * https://github.com/firebase/superstatic/blob/master/LICENSE */ 'use strict'; var setHeaders = require('./headers'); var fs = require('fs'); module.exports = function(spec) { var defaultErrorContent; if (spec.errorPage) { defaultErrorContent = fs.readFileSync(spec.errorPage, 'utf8'); } return function(req, res, next) { var config = req.superstatic; var errorPage = config.errorPage || '/404.html'; setHeaders(spec)({ superstatic: config, url: errorPage }, res, function() { var handles = [{file: errorPage, status: 404}]; if (defaultErrorContent) { handles.push({data: defaultErrorContent, status: 404}); } res.superstatic.handle(handles, next); }); }; };