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


TypeScript Router.use方法代码示例

本文整理汇总了TypeScript中express.Router.use方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Router.use方法的具体用法?TypeScript Router.use怎么用?TypeScript Router.use使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在express.Router的用法示例。


在下文中一共展示了Router.use方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: setDummyRouting

function setDummyRouting(app: Express){
    let dummyRouter: Router = Router();

    let dummyServePath: string = path.join(__dirname, '../public/views/dummy');
    dummyRouter.use( express.static(dummyServePath) );

    dummyRouter.get('/test', function(req : Request, res: Response){
        res.send(dummy.getDummyMessage());
    })

    dummyRouter.get('/forajax', function(req : Request, res: Response){
        res.send('This was retrieved through ajax!');
    })

    app.use('/dummy/', dummyRouter);
}
开发者ID:peerhenry,项目名称:pulety,代码行数:16,代码来源:routeconfig.ts

示例2: router

 async router(base:Router, options?: RouterOptions): Promise<Router> {
   let r = Router(options);
   let knownPaths = new Set();
   let promises: Promise<Router>[] = [];
   this.operations.forEach((operation: Operation) => {
     knownPaths.add(operation.path);
     promises.push(operation.router(r));
   });
   await Promise.all(promises);
   knownPaths.forEach(path => {
     r.all(path, (req: APIRequest, res: APIResponse, next: NextFunction) => {
       next(API.newError(405, 'Method Not Allowed', "The API Endpoint doesn't support the specified HTTP method for the given resource"));
     });
   });
   base.use(this.basePath, r);
   return r;
 }
开发者ID:vivocha,项目名称:arrest,代码行数:17,代码来源:resource.ts

示例3: registerInterceptor

 private registerInterceptor(interceptor: Interceptor) {
     this.router.use((request:Request, response: Response, next: NextFunction) => {
         interceptor.preHandle(request, response)
             .then(next).catch((error) => console.log(error));
     });
 }
开发者ID:PesanskiGoran,项目名称:framework,代码行数:6,代码来源:Dispatcher.ts

示例4: require

/**
 * Created by Franz on 4/30/2016.
 */
import express = require('express');
import {Router} from "express";
import securityRouter from './securityRouter';
import someThingRouter from './someThingRouter';

let topRouter:Router = express.Router();

topRouter.use('/api/security', securityRouter);
topRouter.use('/api/something', someThingRouter);

export default topRouter;
开发者ID:FranzZemen,项目名称:nodets-scaffolding,代码行数:14,代码来源:topRouter.ts

示例5: Router

import { Router, Response } from "express";
import { verify } from "jsonwebtoken";
import { secret } from "../config";

const protectedRouter: Router = Router();

protectedRouter.use(function(req: any, res: Response, next) {
    const token = req.headers.auth;
    verify(token, secret, function(tokenError) {
        if (tokenError) {
            return res.status(403).json({
                message: "Invalid token, please Log in first"
            });
        }

        next();
    });
});

protectedRouter.get("/", function(req, res) {
    res.json({
        text: "Greetings, you have valid token.",
        title: "Protected call"
    });
});

export {protectedRouter}



开发者ID:DevEngage,项目名称:angular2-express-starter,代码行数:27,代码来源:protected.ts

示例6: Router

import { Router, Response, Request, NextFunction } from 'express';
import { verify } from 'jsonwebtoken';
import { secret } from '../config';

const protectedRouter: Router = Router();

protectedRouter.use((request: Request & { headers: { authorization: string } }, response: Response, next: NextFunction) => {
    const token = request.headers.authorization;

    verify(token, secret, function(tokenError) {
        if (tokenError) {
            return response.status(403).json({
                message: 'Invalid token, please Log in first'
            });
        }

        next();
    });
});

protectedRouter.get('/', (request: Request, response: Response) => {
    response.json({
        text: 'Greetings, you have valid token.',
        title: 'Protected call'
    });
});

export { protectedRouter }


开发者ID:akazimirov,项目名称:domic,代码行数:28,代码来源:protected.ts

示例7: require

import * as async from 'async';
import * as bcrypt from 'bcrypt';
import {Router, Response} from 'express';
import {NextFunction} from 'express';
import jsonApiSerializer = require('jsonapi-serializer');
import {IUser, User} from '../models/user';
import {Authentication} from '../authentication';
import {userSerializer} from '../serializers/user-serializer';
import {IRequest} from '../interfaces';

namespace UserRoutes {
  'use strict';

  export const router: Router = Router();
  router.use(function (req, res, next) {
    console.log('this is just an empty middleware');
    next();
  });
  router.post('/', function (req: IRequest, res: Response, next: NextFunction): void {
    console.log('let us create a user please');
    // validate incoming data:
    // we need a user name of min 6 char long
    req.checkBody('data.type', 'not a user record').equals('users');
    req.checkBody('data.attributes.name', 'not alphanumeric').isAlphanumeric();
    req.checkBody('data.attributes.name', 'too short (3 char min)').len(3, undefined);
    // we need an email that is a proper email
    req.checkBody('data.attributes.email', 'invalid email').isEmail();
    // we need a password that is at least 6 char long
    req.checkBody('data.attributes.password', 'password too short  (6 char min)').len(6, undefined);

    let errors: Dictionary<any> = req.validationErrors(true);
    // if any of these parameter does not fit the criteria
开发者ID:dadakoko,项目名称:play-server,代码行数:32,代码来源:users.ts

示例8: Router

import { NextFunction, Request, Response, Router } from "express";
import { verify } from "jsonwebtoken";
import { secret } from "../config";

const protectedRouter: Router = Router();

type AuthorizedRequest = Request & { headers: { authorization: string } };

protectedRouter.use((request: AuthorizedRequest, response: Response, next: NextFunction) => {
    const token = request.headers.authorization;

    verify(token, secret, (tokenError) => {
        if (tokenError) {
            return response.status(403).json({
                message: "Invalid token, please Log in first",
            });
        }

        next();
    });
});

protectedRouter.get("/", (request: Request, response: Response) => {
    response.json({
        text: "Greetings, you have valid token.",
        title: "Protected call",
    });
});

export { protectedRouter };
开发者ID:venki143mca,项目名称:TeamBirthday,代码行数:30,代码来源:protected.ts

示例9: Router

import { Request, Response, Router } from "express";
import { userRoutes } from "./user.routes";

const apiRoutes: Router = Router();

apiRoutes.get("/pop", (req, res, next) => {
    // This isn't part of API and is just used from a browser or curl to test that
    // "/pop" is being routed correctly.

    const testObject = {
        "AppName": "MongoPop",
        "Version": 1.0
    }
    res.json(testObject);
});

apiRoutes.use("/users", userRoutes);

export { apiRoutes };
开发者ID:relevantmedia,项目名称:angular2_mean,代码行数:19,代码来源:api.routes.ts

示例10: Router

//ver https://github.com/expressjs/session y https://github.com/vladotesanovic/angular2-express-starter/tree/master/server/routes
import { Router, Response, Request } from "express";
import { } from "express-session"

const protectedRouter: Router = Router();

protectedRouter.use(function(req: Request, res: Response, next) {
    if(req.session){
        next();
    }
    //redirect("/login")
});

export { protectedRouter }





开发者ID:hernan91,项目名称:ww3,代码行数:14,代码来源:protected.ts


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