本文整理汇总了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;未经允许,请勿转载。 |
请发表评论