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


TypeScript spdy.createServer函數代碼示例

本文整理匯總了TypeScript中spdy.createServer函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createServer函數的具體用法?TypeScript createServer怎麽用?TypeScript createServer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了createServer函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

  it('should support custom base', (done: any) => {
    function Pseuver(options: spdy.ServerOptions, listener: () => void) {
      https.Server.call(this, options, listener);
    }
    util.inherits(Pseuver, https.Server);

    const server = spdy.createServer(Pseuver, fixtures.keys, (req: any, res: any) => {
      assert.equal(req.isSpdy, res.isSpdy);
      assert.equal(req.spdyVersion, res.spdyVersion);
      assert(!req.isSpdy);
      assert.equal(req.spdyVersion, 1);

      res.writeHead(200);
      res.end();
    });

    server.listen(fixtures.port, () => {
      const req = https.request({
                                agent: false,
                                rejectUnauthorized: false,
                                NPNProtocols: [ 'http/1.1' ],
                                port: fixtures.port,
                                method: 'GET',
                                path: '/'
                              }, (res: any) => {
        assert.equal(res.statusCode, 200);
        res.resume();
        res.on('end', () => {
          server.close(done);
        });
      });

      req.end();
    });
  });
開發者ID:Jeremy-F,項目名稱:DefinitelyTyped,代碼行數:35,代碼來源:spdy-tests.ts

示例2: beforeEach

      beforeEach((done: any) => {
        hmodule = plain ? http : https;

        const options = util._extend({
                                     spdy: {
                                       plain,
                                       'x-forwarded-for': true
                                     }
                                   }, fixtures.keys);
        server = spdy.createServer(options, (req: any, res: any) => {
          res.writeHead(200, req.headers);
          res.end();
        });

        server.listen(fixtures.port, () => {
          agent = spdy.createAgent({
                                     rejectUnauthorized: false,
                                     port: fixtures.port,
                                     spdy: {
                                       'x-forwarded-for': '1.2.3.4',
                                       plain,
                                       protocol: plain ? npn : null,
                                       protocols: [ npn ]
                                     }
                                   });

          done();
        });
      });
開發者ID:Jeremy-F,項目名稱:DefinitelyTyped,代碼行數:29,代碼來源:spdy-tests.ts

示例3: createServer

/**
 * Creates an HTTP(S) server
 * @param app
 * @param {ServerOptions} options
 * @returns {Promise<http.Server>} Promise of server
 */
async function createServer(
    app: express.Application, options: ServerOptions): Promise<http.Server> {
  const opt: any = {spdy: {protocols: [options.protocol]}};

  if (isHttps(options.protocol)) {
    const keys = await getTLSCertificate(options.keyPath, options.certPath);
    opt.key = keys.key;
    opt.cert = keys.cert;
  } else {
    opt.spdy.plain = true;
    opt.spdy.ssl = false;
  }

  return http.createServer(opt, app as any);
}
開發者ID:iblancasa,項目名稱:polyserve,代碼行數:21,代碼來源:start_server.ts

示例4: require

if (process.env.NODE_ENV === "production")
    require("newrelic");

var PORT = process.env.PORT || 3333;

import * as express from "express";
import * as os from "os";
import * as http2 from "spdy";
import * as fs from "fs";
import {RoutesConfig} from "./config/routes.conf";
import {DBConfig} from "./config/db.conf";
import {Routes} from "./routes/index";

const app = express();

RoutesConfig.init(app);
DBConfig.init();
Routes.init(app, express.Router());

const opts = {
  key: fs.readFileSync(__dirname + "/cert/server.key"),
  cert: fs.readFileSync(__dirname + "/cert/server.crt")
}

http2.createServer(opts, app)
     .listen(PORT, () => {
       console.log(`up and running @: ${os.hostname()} on port: ${PORT}`);
       console.log(`enviroment: ${process.env.NODE_ENV}`);
     });
開發者ID:bernardbr,項目名稱:generator-ng-fullstack,代碼行數:29,代碼來源:server_http2.ts

示例5: routerCb

const PORT = process.env.PORT || 3333;

import * as fs from "fs";
import * as os from "os";
import * as http2 from "spdy";
import * as Koa from "koa";
import * as routerCb from "koa-router";
import * as RoutesConfig from "./config/routes.conf";
import * as DBConfig from "./config/db.conf";
import * as Routes from "./routes/index";

const router = routerCb();

const app = new Koa();

RoutesConfig.init(app, router);
DBConfig.init();
Routes.init(app, router);

const opts = {
  key: fs.readFileSync(__dirname + "/cert/server.key"),
  cert: fs.readFileSync(__dirname + "/cert/server.crt")
}

http2.createServer(opts, app.callback())
     .listen(PORT, () => {
       console.log(`up and running @: ${os.hostname()} on port: ${PORT}`);
       console.log(`enviroment: ${process.env.NODE_ENV}`);
     });
開發者ID:bernardbr,項目名稱:generator-ng-fullstack,代碼行數:29,代碼來源:server_http2.ts

示例6: createServer

  createServer() {
    let https = this.options.https

    if (https) {
      // for keep supporting CLI parameters
      if (typeof https === 'boolean') {
        https = {
          requestCert: false,
        }
      }

      let fakeCert
      if (!https.key || !https.cert) {
        // Use a self-signed certificate if no certificate was configured.
        // Cycle certs every 24 hours
        const certPath = join(__dirname, '../../ssl/server.pem')
        let certExists = fs.existsSync(certPath)

        if (certExists) {
          const certStat = fs.statSync(certPath)
          const certTtl = 1000 * 60 * 60 * 24
          const now = new Date()

          // cert is more than 30 days old, kill it with fire
          if ((now.getTime() - certStat.ctime.getTime()) / certTtl > 30) {
            console.log('SSL Certificate is more than 30 days old. Removing.')
            fs.unlinkSync(certPath)
            certExists = false
          }
        }

        if (!certExists) {
          console.log('Generating SSL Certificate')
          const attrs = [{ name: 'commonName', value: 'localhost' }]
          const pems = selfsigned.generate(attrs, {
            algorithm: 'sha256',
            days: 30,
            keySize: 2048,
            extensions: [
              {
                name: 'basicConstraints',
                cA: true,
              },
              {
                name: 'keyUsage',
                keyCertSign: true,
                digitalSignature: true,
                nonRepudiation: true,
                keyEncipherment: true,
                dataEncipherment: true,
              },
              {
                name: 'subjectAltName',
                altNames: [
                  {
                    // type 2 is DNS
                    type: 2,
                    value: 'localhost',
                  },
                  {
                    type: 2,
                    value: 'localhost.localdomain',
                  },
                  {
                    type: 2,
                    value: 'lvh.me',
                  },
                  {
                    type: 2,
                    value: '*.lvh.me',
                  },
                  {
                    type: 2,
                    value: '[::1]',
                  },
                  {
                    // type 7 is IP
                    type: 7,
                    ip: '127.0.0.1',
                  },
                  {
                    type: 7,
                    ip: 'fe80::1',
                  },
                ],
              },
            ],
          })

          fs.writeFileSync(certPath, pems.private + pems.cert, {
            encoding: 'utf-8',
          })
        }
        fakeCert = fs.readFileSync(certPath)
      }

      https.key = https.key || fakeCert
      https.cert = https.cert || fakeCert

      if (!https.spdy) {
//.........這裏部分代碼省略.........
開發者ID:aranja,項目名稱:tux,代碼行數:101,代碼來源:Server.ts


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