本文整理汇总了TypeScript中send.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: run
async function run(request, response, sha: string) {
let pathname = request.path;
try {
if (pathname.endsWith('/')) {
pathname += 'index.html';
}
let parts = pathname.split('/');
if (sha === null && parts.length === 2 && !pathname.endsWith('/')) {
response.redirect('/run' + request.url + '/');
return;
}
let partsIndex = 1;
if (sha === null) {
sha = parts[1];
partsIndex = 2;
}
await cache(null, sha, 'html5');
let newparts = ['..', 'Projects', 'Checkouts', sha, 'build', 'html5'];
for (let i = partsIndex; i < parts.length; ++i) {
newparts.push(parts[i]);
}
send(request, path.resolve(newparts.join('/'))).pipe(response);
}
catch (error) {
console.log('Illegal path: ' + pathname);
console.log(error);
response.status(200).send('Not found.');
}
}
示例2: cache
app.use('/projects/', async (request, response, next) => {
let pathname = request.path;
try {
if (pathname.endsWith('/')) {
pathname += 'index.html';
}
let parts = pathname.split('/');
let sha = parts[1];
let filename = parts[parts.length - 1];
await cache(null, sha);
let newparts = ['..', 'Projects', 'Checkouts', sha, 'build'];
if (filename.endsWith('.essl')) {
newparts.push('html5worker-resources');
}
else {
newparts.push('html5worker');
}
for (let i = 2; i < parts.length; ++i) {
newparts.push(parts[i]);
}
send(request, path.resolve(newparts.join('/'))).pipe(response);
}
catch (error) {
console.log('Illegal path: ' + pathname);
console.log(error);
response.status(200).send('Not found.');
}
});
示例3: async
app.use('/archives/', async (request, response, next) => {
if (!request.path.endsWith('.zip')) {
response.status(200).send('Not found.');
}
response.setHeader('Content-disposition', 'attachment; filename=' + request.path.substr(1));
response.setHeader('Content-Type', 'application/zip');
let filepath = path.resolve(path.join('..', 'Projects', 'Archives', request.path.substr(1)));
send(request, filepath).pipe(response);
});
示例4: TypeError
sendFile(path, options, callback) {
var done = callback;
var req = this.request;
var res = this;
var next = request.next;
var opts = options || {};
if (!path) {
throw new TypeError('path argument is required to res.sendFile');
}
// support function as second arg
if (typeof options === 'function') {
done = options;
opts = {};
}
if (!opts.root && !isAbsolute(path)) {
throw new TypeError('path must be absolute or specify root to res.sendFile');
}
// create file stream
var pathname = encodeURI(path);
var file = send(req, pathname, opts);
// transfer
sendfile(res, file, opts, function (err) {
if (done) return done(err);
if (err && err.code === 'EISDIR') return next();
// next() all but write errors
if (err && err.code !== 'ECONNABORTED' && err.syscall !== 'write') {
next(err);
}
});
}