本文整理汇总了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;
}
示例2: create
export function create (options) {
const app = connect();
const mw = middleware.getMiddleware(options);
app.stack = mw.middleware;
return getServer(app, options);
}
示例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));
}
示例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');
});
示例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;
}
示例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;
}
示例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!');
});
示例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 );
});
}
示例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);