本文整理匯總了TypeScript中express.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: express
}).then((conn) => {
const defaultParser = bodyParser.urlencoded({ extended: true });
const server = express();
const db: ISql = new Sql();
const emailSender: IEmailSender = new EmailSender();
// controller declarations
const homeController = new HomeController(db);
const newController = new NewController(db, emailSender);
const movieController = new MovieController(db);
const playerController = new PlayerController(db);
// server setup
server.use(defaultParser);
server.use(express.static("dist/public"));
server.use(favicon(path.join(__dirname, "public", "favicon.ico")));
server.set("view engine", "pug");
server.set("views", "dist/views");
// route declarations
server.get("/", homeController.index.bind(homeController));
server.get("/new", newController.index.bind(newController));
server.post("/new", newController.postNew.bind(newController));
server.get("/movies/:id(\\d+)", movieController.get.bind(movieController));
server.get("/players/:id(\\d+)", playerController.get.bind(playerController));
server.get("/:teamId", homeController.indexTeam.bind(homeController));
server.listen(3000);
}).catch((error) => {
示例2: function
module.exports = function () {
var app = express();
require('../app/routes/index.server.routes.js')(app);
return app;
//};
//var morgan = require('morgan');
//var compress = require('compression');
//var bodyParser = require('body-parser');
//var methodOverride = require('method-override');
//module.exports = function () {
// var app = express();
// if (process.env.NODE_ENV === 'development') {
// app.use(morgan('dev'));
// } else if (process.env.NODE_ENV === 'production') {
// app.use(compress());
// }
// app.use(bodyParser.urlencoded({
// extended: true
// }));
// app.use(bodyParser.json());
// app.use(methodOverride());
// app.set('views', './app/views');
// app.set('view engine', 'ejs');
// require('../app/routes/index.server.routes.js')(app);
// return app;
};
示例3: function
module.exports = function(ROOT) {
var app = express();
var {ng2engine} = require('angular2-universal-preview');
// rendering engine
app.engine('ng2.html', ng2engine);
app.set('views', path.join(ROOT, 'examples'));
app.set('view engine', 'ng2.html');
app.set('view options', { doctype: 'html' });
var routes = require('./routes');
var api = require('./api');
var graphApi = require('./graph_api');
app.use(serveStatic(`${ROOT}/dist`));
app.use(serveStatic(`${ROOT}/examples/app/public`));
app.use('/api', api(ROOT));
app.use('/graph_api', api(ROOT));
app.use(routes(ROOT));
app.use(morgan('dev'));
app.get('*', function(req, res) {
res.json({
'route': 'Sorry this page does not exist!'
});
});
return app;
};
示例4: Promise
export const start = async (port: string) => {
await MongooseClient.InitMongoConnection();
const app = express();
const appRootUrl = siteName ? `https://${siteName}.azurewebsites.net` : `http://localhost:${port}`;
initPassport(appRootUrl);
enableSessions(app, SocketServer);
initSockets();
app.use(json())
app.use(passport.initialize());
app.use(passport.session());
const server = createServer(app);
SocketServer.attach(server);
app.use(Routes);
await new Promise(resolve => {
server.listen(port, () => {
console.log(`Server listening at port ${port}`);
resolve()
});
})
return async function close() {
await new Promise(resolve => server.close(resolve))
await MongooseClient.disconnect()
}
};
示例5: require
constructor(bot:any, config:any) {
this.name = 'webserver';
this.title = 'Webserver';
this.description = "Webserver module for Modubot";
this.version = '0.1';
this.author = 'Kamal Nasser';
this.bot = bot;
this.database = bot.database;
this.client = bot.client;
this.commands = {};
this.config = config;
this.plugins = [];
var express = require('express');
this.port = this.config.port || 8888;
this.server = express();
this.server.use(express.static(__dirname + '/public'));
this.server.set('views', __dirname + '/views');
this.server.set('view engine', 'jade');
this.server.locals.bot = this.bot;
this.server.locals.plugins = this.plugins;
if(this.server.listen(this.port)){
console.log('Webserver listening on port http://localhost:' + this.port);
} else {
console.log('Error binding to port ' + this.port);
}
this.setupRoutes();
this.loadPlugins();
}
示例6: Promise
test('downloadStream() for media', async t => {
const app = express()
app.use(require('cookie-parser')())
app.get('/ding', function(req, res) {
// console.log(req.cookies)
t.ok(req.cookies, 'should has cookies in req')
t.is(req.cookies.life, '42', 'should has a cookie named life value 42')
res.end('dong')
})
const server = http.createServer(app)
server.on('clientError', (err, socket) => {
t.fail('server on clientError' + err)
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n')
})
server.listen(65534)
try {
const s = await Misc.urlStream('http://127.0.0.1:65534/ding', [{name: 'life', value: 42}])
await new Promise((resolve, reject) => {
s.on('data', (chunk) => {
// console.log(`BODY: ${chunk}`)
t.is(chunk.toString(), 'dong', 'should success download dong from downloadStream()')
server.close()
resolve()
})
s.on('error', reject)
})
} catch (e) {
t.fail('downloadStream() exception: ' + e.message)
}
})
示例7: function
module.exports = function(ROOT) {
var app = express();
var {expressEngine} = require('angular2-universal-preview');
// rendering engine
app.engine('ng2.html', expressEngine);
app.set('views', path.join(ROOT));
app.set('view engine', 'ng2.html');
app.set('view options', { doctype: 'html' });
app.set('json spaces', 2);
var routes = require('./routes');
var api = require('./api');
var graphApi = require('./graph_api');
app.use(serveStatic(path.join(ROOT, 'dist'), {index: false}));
app.use(serveStatic(path.join(ROOT, 'public'), {index: false}));
app.use('/api', api(ROOT));
app.use('/graph_api', api(ROOT));
app.use(routes(ROOT));
app.use(morgan('dev'));
app.get('*', function(req, res) {
res.json({
'url': req.originalUrl,
'route': 'Sorry this page does not exist!'
});
});
return app;
};
示例8: listen
// Listen takes the same arguments as http.Server.listen.
public async listen(...opts: Array<any>): Promise<ServerInfo> {
// This class is the easy mode for people who don't create their own express
// object, so we have to create it.
const app = express();
// provide generous values for the getting started experience
super.applyMiddleware({
app,
path: '/',
bodyParserConfig: { limit: '50mb' },
cors:
typeof this.cors !== 'undefined'
? this.cors
: {
origin: '*',
},
});
const httpServer = http.createServer(app);
this.httpServer = httpServer;
if (this.subscriptionServerOptions) {
this.installSubscriptionHandlers(httpServer);
}
await new Promise(resolve => {
httpServer.once('listening', resolve);
// If the user passed a callback to listen, it'll get called in addition
// to our resolver. They won't have the ability to get the ServerInfo
// object unless they use our Promise, though.
httpServer.listen(...(opts.length ? opts : [{ port: 4000 }]));
});
return this.createServerInfo(httpServer, this.subscriptionsPath);
}
示例9: require
(function () {
"use strict";
var express = require('express');
var routes = require('./routes');
var app = express();
app.configure(function () {
app.use(express.bodyParser());
app.use(express.static(__dirname + '/public'));
app.get('/api/todo', routes.getallTodoes);
app.get('/api/todo/MetaData', routes.getMetadata);
app.get('/api/todo/:todoid', routes.getTodoById);
app.post('/api/todo', routes.saveChanges);
app.get('/api/faketodo', routes.getallFakeTodoes);
app.get('/api/faketodo/MetaData', routes.getFakeMetaData);
app.get('/api/faketodo/:todoid', routes.getFakeTodoById);
app.post('/api/faketodo', routes.saveFakeChanges);
});
console.log('listing on port::' + process.env.PORT);
app.listen(process.env.PORT || 9000);
})();
示例10: constructor
constructor() {
var express = require('express'),
logger = require('morgan'),
session = require('express-session')
var Grant = require('grant-express'),
grant = new Grant(require('./server/OAuthConfigure.json'))
var app = express()
app.use(logger('dev'))
// REQUIRED:
app.use(session({
secret: 'very secret'
}))
// mount grant
app.use(grant)
app.get('/handle_visualstudio_callback', function(req, res) {
console.log(req.query)
res.end(JSON.stringify(req.query, null, 2))
});
this.setupHttpServer(app);
}