本文整理匯總了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);
});
};