当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript https.ServerResponse类代码示例

本文整理汇总了TypeScript中https.ServerResponse的典型用法代码示例。如果您正苦于以下问题:TypeScript ServerResponse类的具体用法?TypeScript ServerResponse怎么用?TypeScript ServerResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ServerResponse类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: 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);
                        })
//.........这里部分代码省略.........
开发者ID:wavesplatform,项目名称:WavesGUI,代码行数:101,代码来源:utils.ts

示例2:

 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);
 });
开发者ID:wavesplatform,项目名称:WavesGUI,代码行数:8,代码来源:utils.ts

示例3: minify

 .then((template) => {
     const code = minify(template, {
         collapseWhitespace: true // TODO @xenohunter check html minify options
     });
     res.end(code);
 });
开发者ID:wavesplatform,项目名称:WavesGUI,代码行数:6,代码来源:utils.ts

示例4: getInitScript

 return getInitScript(connectionType, buildType, type).then((script) => {
     res.end(script);
 });
开发者ID:wavesplatform,项目名称:WavesGUI,代码行数:3,代码来源:utils.ts

示例5: readFile

 return readFile(path, 'utf8').then((file) => {
     res.end(file);
 });
开发者ID:wavesplatform,项目名称:WavesGUI,代码行数:3,代码来源:utils.ts


注:本文中的https.ServerResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。