本文整理汇总了TypeScript中https.ServerResponse.setHeader方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ServerResponse.setHeader方法的具体用法?TypeScript ServerResponse.setHeader怎么用?TypeScript ServerResponse.setHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类https.ServerResponse
的用法示例。
在下文中一共展示了ServerResponse.setHeader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
Object.keys(resp.headers).forEach((name) => {
if (name !== 'transfer-encoding' && name !== 'connection' && !res.getHeader(name)) {
res.setHeader(name, resp.headers[name]);
}
});
示例2: function
return function (req: IncomingMessage, res: ServerResponse) {
const url = req.url.replace(/\?.*/, '');
if (url.includes('/package.json')) {
res.end(readFileSync(join(__dirname, '..', 'package.json')));
} else if (isTradingView(url)) {
get(`https://client.wavesplatform.com/${url}`, (resp: IncomingMessage) => {
let data = new Buffer('');
// A chunk of data has been recieved.
resp.on('data', (chunk: Buffer) => {
data = Buffer.concat([data, chunk]);
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
Object.keys(resp.headers).forEach((name) => {
if (name !== 'transfer-encoding' && name !== 'connection' && !res.getHeader(name)) {
res.setHeader(name, resp.headers[name]);
}
});
res.end(data);
});
});
return null;
}
if (buildType !== 'dev') {
if (isPage(req.url)) {
const path = join(__dirname, '..', 'dist', type, connectionType, buildType, 'index.html');
return readFile(path, 'utf8').then((file) => {
res.end(file);
});
}
return routeStatic(req, res, connectionType, buildType, type);
} else {
if (buildType === 'dev' && req.url.includes('init.js')) {
return getInitScript(connectionType, buildType, type).then((script) => {
res.end(script);
});
}
}
if (url.indexOf('/locales') === 0) {
const [lang, ns] = url.replace('/locales/', '')
.replace(/\?.*/, '')
.replace('.json', '')
.split('/');
const cachePath = join(process.cwd(), '.cache-download', 'locale', lang, `${ns}.json`);
if (existsSync(cachePath)) {
const data = readFileSync(cachePath);
res.end(data);
} else {
res.statusCode = 404;
res.end('Not found!');
}
return null;
}
if (url.indexOf('/img/images-list.json') !== -1) {
res.setHeader('Content-Type', 'application/json');
const images = getFilesFrom(
join(__dirname, '../src/img'),
['.svg', '.png', '.jpg'],
(name, path) => path.indexOf('no-preload') === -1
).map(moveTo(join(__dirname, '../src')));
res.end(JSON.stringify(images));
return null;
}
if (isPage(url)) {
return prepareHTML({
target: join(__dirname, '..', 'src'),
connection: connectionType,
type,
}).then((file) => {
res.end(file);
});
} else if (isTemplate(url)) {
readFile(join(__dirname, '../src', url), 'utf8')
.then((template) => {
const code = minify(template, {
collapseWhitespace: true // TODO @xenohunter check html minify options
});
res.end(code);
});
} else if (isLess(url)) {
const theme = req.url.match(/theme=(.+),?/)[1];
readFile(join(__dirname, '../src', url), 'utf8')
.then((style) => {
(render as any)(style, {
filename: join(__dirname, '../src', url),
paths: join(__dirname, `../src/themeConfig/${theme}`)
} as any)
.then(function (out) {
res.setHeader('Content-type', 'text/css');
res.end(out.css);
})
//.........这里部分代码省略.........