async function route(options, request, response) { const name = ponse.getPathName(request); const gzip = true; const p = { request, response, gzip, name, }; config('prefix', prefixer(request.baseUrl)); const rootName = name.replace(CloudFunc.FS, '') || '/'; const fullPath = root(rootName); const [error, dir] = await tryToCatch(read, fullPath); const {html} = options; if (!error) return sendIndex(p, buildIndex(html, { ...dir, path: format.addSlashToEnd(rootName), })); if (error.code !== 'ENOTDIR') return ponse.sendError(error, p); const [realPathError, pathReal] = await tryToCatch(realpath, fullPath); ponse.sendFile({ ...p, name: realPathError ? name : pathReal, gzip: false, }); }
async function patch(request, response) { const name = 'config.json'; const cache = false; const options = { name, request, response, cache, }; const [e] = await tryToCatch(patchConfig, options); if (e) ponse.sendError(e, options); }
files.readPipe(names, stream).catch((error) => { if (!error) return; const msg = error.message; if (response.headersSent) return stream.end(msg); const name = ponse.getPathName(request); ponse.sendError(msg, { name, gzip, request, response, }); });
sendData(params, function(error, options, data) { params.gzip = !error; if (!data) { data = options; options = {}; } if (options.name) params.name = options.name; if (options.gzip !== undefined) params.gzip = options.gzip; if (options.query) params.query = options.query; if (error) ponse.sendError(error, params); else ponse.send(data, params); });
sendData(params, (error, options, data) => { params.gzip = !error; if (!data) { data = options; options = {}; } if (options.name) params.name = options.name; if (options.gzip !== undefined) params.gzip = options.gzip; if (options.query) params.query = options.query; if (error) return ponse.sendError(error, params); ponse.send(data, params); });
save(function(error) { if (error) ponse.sendError(error, options); else ponse.send(data, options); });