本文整理汇总了TypeScript中@azure-iot/hal/api.route函数的典型用法代码示例。如果您正苦于以下问题:TypeScript route函数的具体用法?TypeScript route怎么用?TypeScript route使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了route函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: initialize
export async function initialize(): Promise<express.Express> {
const app = express();
// uncomment after placing your favicon in /public
// app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
const config = Config.get();
// if caching is not enabled, then we need to disable it
if (!config.CachingEnabled) {
// disables etag caching (304s)
app.disable('etag');
// force all responses to have a no-cache header; can be overriden in handlers
app.use((req, res, next) => {
res.header('Cache-Control', 'no-cache, no-store, must-revalidate');
res.header('Pragma', 'no-cache');
res.header('Expires', '0');
next();
});
}
if (config.Auth) {
// initialize authentication module and set up middleware that
// ensures the user is authenticated:
const auth = await Authentication.initialize(
app,
config.Auth.loginUrl,
config.Auth.sessionSecret,
config.Auth.mongoUri);
app.use(auth.ensureAuthenticated);
}
if (config.ConsoleReporting === 'both' || config.ConsoleReporting === 'client') {
app.use(logger('dev'));
}
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
// initialize routes:
app.use(appRoute);
app.use('/api/devices', route(new DeviceAPI(config.IotHubConnectionString)));
app.use('/api/jobs', route(new JobAPI(config.IotHubConnectionString)));
app.use('/api/discovery', hal.discovery);
// catch 404 and forward to error handler
app.use('/*', error404Handler);
// error handlers
app.use(error500Handler);
return app;
}
示例2: initialize
export async function initialize(): Promise<express.Express> {
const app = express();
// uncomment after placing your favicon in /public
// app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
const config = Config.get();
if (config.Auth) {
// initialize authentication module and set up middleware that
// ensures the user is authenticated:
const auth = await Authentication.initialize(
app,
config.Auth.loginUrl,
config.Auth.sessionSecret,
config.Auth.mongoUri);
app.use(auth.ensureAuthenticated);
}
if (config.ConsoleReporting === 'both' || config.ConsoleReporting === 'client') {
app.use(logger('dev'));
}
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
// initialize routes:
app.use(appRoute);
app.use('/api/devices', route(new DeviceAPI(config.IotHubConnectionString)));
app.use('/api/jobs', route(new JobAPI(config.IotHubConnectionString)));
app.use('/api/discovery', hal.discovery);
// catch 404 and forward to error handler
app.use('/*', error404Handler);
// error handlers
app.use(error500Handler);
return app;
}
示例3: next
@route(Method.GET, '/:Id')
@provides('get')
@hal()
@logISR()
GetJob(req: express.Request, res: express.Response, next) {
this.jobClient.getJob(req.params.Id, function(error, result: JobResponse) {
if (error) {
return next(error);
}
res.json(result);
});
};