當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript send.default函數代碼示例

本文整理匯總了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.');
	}
}
開發者ID:KTXSoftware,項目名稱:KodeGarden,代碼行數:31,代碼來源:kodegarden.ts

示例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.');
	}
});
開發者ID:KTXSoftware,項目名稱:KodeGarden,代碼行數:30,代碼來源:kodegarden.ts

示例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);
});
開發者ID:KTXSoftware,項目名稱:KodeGarden,代碼行數:9,代碼來源:kodegarden.ts

示例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);
            }
        });
    }
開發者ID:yogendrap,項目名稱:PlZoo,代碼行數:36,代碼來源:Response.ts


注:本文中的send.default函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。