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


TypeScript api.route函数代码示例

本文整理汇总了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;
}
开发者ID:manuelmeyer1,项目名称:azure-iot-device-management,代码行数:56,代码来源:server.ts

示例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;
}
开发者ID:habukira,项目名称:Azure-azure-iot-device-management,代码行数:42,代码来源:server.ts

示例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);
     });
 };
开发者ID:habukira,项目名称:Azure-azure-iot-device-management,代码行数:12,代码来源:jobAPI.ts


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