Exemplo n.º 1
0
  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();
    });
  });
Exemplo n.º 2
0
      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();
        });
      });
Exemplo n.º 3
0
  it('should respond to http/1.1', (done: any) => {
    const server = spdy.createServer(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();
    });
  });
Exemplo n.º 4
0
/**
 * 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);
}
Exemplo n.º 5
0
      beforeEach((done: any) => {
        hmodule = plain ? http : https;

        const options = util._extend({
                                     spdy: {
                                       plain
                                     }
                                   }, fixtures.keys);
        server = spdy.createServer(options, (req: any, res: any) => {
          let body = '';
          req.on('data', (chunk: any) => {
            body += chunk;
          });
          req.on('end', () => {
            res.writeHead(200, req.headers);
            res.addTrailers({ trai: 'ler' });

            const push = res.push('/push', {
              request: {
                push: 'yes'
              }
            }, (err: any) => {
              assert(!err);

              push.end('push');
              push.on('error', () => {
              });

              res.end(body || 'okay');
            });
          });
        });

        server.listen(fixtures.port, () => {
          agent = spdy.createAgent({
                                     rejectUnauthorized: false,
                                     port: fixtures.port as number,
                                     spdy: {
                                       plain,
                                       protocol: plain ? npn : null,
                                       protocols: [ npn ]
                                     }
                                   });

          done();
        });
      });
Exemplo n.º 6
0
    beforeEach((done: any) => {
      server = spdy.createServer(util._extend({
                                                spdy: {
                                                  'x-forwarded-for': true,
                                                  plain
                                                }
                                              }, fixtures.keys));

      server.listen(fixtures.port, () => {
        const socket = (plain ? net : tls).connect({
                                                   rejectUnauthorized: false,
                                                   port: fixtures.port,
                                                   NPNProtocols: [ npn ]
                                                 }, () => {
          client = transport.connection.create(socket, {
            protocol,
            isServer: false
          });
          client.start(version);
          done();
        });
      });
    });
Exemplo n.º 7
0
 it('should accept express app', () => {
   const express = require('express');
   const app = express();
   spdy.createServer({}, app);
 });
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}`);
     });
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}`);
     });
Exemplo n.º 10
0
Arquivo: Server.ts Projeto: aranja/tux
  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) {
        https.spdy = {
          protocols: ['h2', 'http/1.1'],
        }
      }

      this.server = spdy.createServer(https, this.app)
    } else {
      this.server = http.createServer(this.app)
    }
  }