當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。