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


TypeScript connect.default函数代码示例

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


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

示例1: app

 function app (middleware: ReturnType<typeof frameguard>): connect.Server {
   const result = connect();
   result.use(middleware);
   result.use((_req: IncomingMessage, res: ServerResponse) => {
     res.end('Hello world!');
   });
   return result;
 }
开发者ID:helmetjs,项目名称:frameguard,代码行数:8,代码来源:index.test.ts

示例2: create

export function create (options) {

    const app = connect();
    const mw  = middleware.getMiddleware(options);

    app.stack = mw.middleware;
    
    return getServer(app, options);
}
开发者ID:b-cuts,项目名称:browser-sync-core,代码行数:9,代码来源:server.ts

示例3: Config

		constructor() {
			
			this.configChangedCallback = this.configChanged;
			this.config = new Config(this.configChangedCallback.bind(this));
			
			//Using connect
			this.app = connect()
				.use(favicon(__dirname + '/pub/images/favicon.ico'))
				.use('/admin', connect_static(__dirname + '/pub', {fallthrough: false}))
				.use(bodyParser.json({ type: '*/*' }))
				.use(
					function(req:any, res: any) {

						
						try {
							console.log(req.body);
							res.setHeader('Content-Type', 'application/json');

							//Do logic
							let commands = req.body["commands"];
							
							//Hard coded for testing purposes
							let ccCommand = commands[0];
							let c: Color = new Color(ccCommand.color);
							
							let result = {
								"color":{
									R: c.getByteArray()[0],
									G: c.getByteArray()[1],
									B: c.getByteArray()[2]	
								}
							};
							
							//response.end('Setting color to ' + c.toString());
							res.end(JSON.stringify(result, null, 2));
						}
						catch (Error) {
							console.error(Error.stack);
						}
					})
					.listen(1234, function() {
						console.log("Listening on port 1234...");
					})
					//Listen to EADDRINUSE (port already in use)			
					.on('error', (function(err: any) { 
						if (err.code === "EADDRINUSE") { 
							console.log("Port already in use. Retrying in "+this.config.getTimeout()+" seconds...");
							setTimeout((function() {
								this.startListening();
							}).bind(this), this.config.getTimeout() * 1000); 
						}
					}).bind(this));

	
		}
开发者ID:dieideeistgut,项目名称:rgb-pi-js,代码行数:55,代码来源:Server.ts

示例4: request

  it('sets header properly', () => {
    const app = connect();
    app.use(ienoopen());
    app.use((_req: IncomingMessage, res: ServerResponse) => {
      res.setHeader('Content-Disposition', 'attachment; filename=somefile.txt');
      res.end('Download this cool file!');
    });

    return request(app).get('/')
      .expect('X-Download-Options', 'noopen');
  });
开发者ID:helmetjs,项目名称:ienoopen,代码行数:11,代码来源:index.test.ts

示例5: start

export function start(port?:number,plugins?:Array<any>):void
{
    var httpPort = port;

    if(!httpPort || httpPort === 0)
    {
        httpPort = 3000;
    }

    var app = connect();

    if(plugins)
    {
        plugins.forEach((plugin)=>{
            app.use(plugin);
        })
    }


    if(env === "development")
    {
        app.use(serveStatic(staticPath,{'index': ['src/client/index.html']}))
    }
    else
    {
        staticPath = path.resolve("./dist/src/client");
        app.use(serveStatic(staticPath))
    }

    server = http.createServer(app).listen(httpPort);


    // Maintain a hash of all connected sockets
    var sockets = {}, nextSocketId = 0;
    server.on('connection', function (socket) {
        // Add a newly connected socket
        var socketId = nextSocketId++;
        sockets[socketId] = socket;

        // Remove the socket when it closes
        socket.on('close', function () {
            delete sockets[socketId];
        });
    });

    console.log("Server started");

    return server;
}
开发者ID:coolchem,项目名称:TODORama-advanced,代码行数:49,代码来源:server.ts

示例6: createConnectApp

function createConnectApp(options: CreateAppOptions = {}) {
  const app = connect();
  // We do require users of ApolloServer with connect to use a query middleware
  // first. The alternative is to add a 'isConnect' bool to ServerRegistration
  // and make qs-middleware be a dependency of this package. However, we don't
  // think many folks use connect outside of Meteor anyway, and anyone using
  // connect is probably already using connect-query or qs-middleware.
  app.use(query());
  const server = new ApolloServer(
    (options.graphqlOptions as ApolloServerExpressConfig) || { schema: Schema },
  );
  // See comment on ServerRegistration.app for its typing.
  server.applyMiddleware({ app: app as any });
  return app;
}
开发者ID:apollostack,项目名称:apollo-server,代码行数:15,代码来源:connectApollo.test.ts

示例7: request

  it('sets headers properly', () => {
    const app = connect();
    app.use((_req: IncomingMessage, res: ServerResponse, next: () => void) => {
      res.setHeader('ETag', 'abc123');
      next();
    });
    app.use(nocache());
    app.use((_req: IncomingMessage, res: ServerResponse) => {
      res.end('Hello world!');
    });

    return request(app).get('/')
      .expect('Surrogate-Control', 'no-store')
      .expect('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate')
      .expect('Pragma', 'no-cache')
      .expect('Expires', '0')
      .expect('ETag', 'abc123')
      .expect('Hello world!');
  });
开发者ID:helmetjs,项目名称:nocache,代码行数:19,代码来源:index.test.ts

示例8: main

function main (): void
{
    try {
        config = loadConfig().get();
        symbols = loadSymbols( config.secpath );
        info( symbols );
    } catch(ex) {
        console.error( ex.message );
        process.exit( 1 );
    }

    lastRequestTime = timeSeconds() - config.interval - 20;
    startTime = timeSeconds();

    var app = connect();

    app.use( "/monitor", (req: http.ServerRequest, res: http.ServerResponse, next: Function) => {
        res.setHeader("content-type", "text/plain");
        var t = uptime();
        res.end( "uptime: "+t.days+"d "+t.hours+"h "+t.minutes+"m\n"+
        "requests: "+requestCount+"\n" );
    });

    app.use( "/", (req: http.ServerRequest, res: http.ServerResponse, next: Function) => {
        // Authorize
        var q = qs.parse(parseurl(req).query);
        if (q.token !== config.token) {
            res.statusCode = 401;
            return res.end('Unauthorized');
        }

        // Rate-limit
        var tm = timeSeconds();
        if (tm - lastRequestTime < config.limit) {
            res.statusCode = 403;
            return res.end('Rate limited');
        }
        lastRequestTime = tm;
        ++requestCount;

        // Send data
        res.setHeader("content-type", "application/json");
        res.end( JSON.stringify(curValues) );
    });

    var server;

    if (config.https) {
        var serverOptions:https.ServerOptions = {
            key: fs.readFileSync(config.key),
            cert: fs.readFileSync(config.cert),
            passphrase: config.pass
        };
        server = https.createServer( serverOptions, app );
    } else {
        server = http.createServer( app );
    }

    connectAPI();

    server.listen( config.port );
    server.once('listening', () => {
        console.log( "Listening on", config.port );
    });
}
开发者ID:mcanet,项目名称:blart,代码行数:65,代码来源:index.ts

示例9: require

///<reference path="../../../typings/tsd.d.ts" />
var connect = require("connect")
    , serveStatic = require("serve-static")
    , http = require("http")
    , compression = require("compression")
    ;

var app = connect();
app.use(serveStatic(__dirname, {
    "index": ["static/index.html"]
}));
app.use(compression());

http.createServer(app).listen(3000);
开发者ID:RedGlow,项目名称:bologna-wars,代码行数:14,代码来源:index.ts


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