How to use the filer.fs.readFile function in filer

To help you get started, we’ve selected a few filer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github humphd / nohost / src / webserver.js View on Github external
function serveFile(path, stats) {
      fs.readFile(path, function(err, contents) {
        if(err) {
          return serveError(path, err);
        }

        const responseData = formatter.formatFile(path, contents, stats);

        // If we are supposed to serve this file or download, add headers
        if(responseData.config.status === 200 && download) {
          responseData.config.headers['Content-Disposition'] =
            formatContentDisposition(path, stats);
        }

        resolve(new Response(responseData.body, responseData.config));
      });
    }