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


TypeScript express.Application类代码示例

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


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

示例1: function

export var setupVerbRoutes = function (baseUrl: string, expressApp: Application) {
  var verbHandler: VerbHandler = new VerbHandler();

  var verbController: VerbController = new VerbController(verbHandler);

  expressApp.get(baseUrl + "verb/get", async (req, res) => {
    verbController.getAll(req, res);
  });

  expressApp.get(baseUrl + "verb/get/:id", async (req, res) => {
    verbController.getOne(req, res);
  });

  expressApp.post(baseUrl + "verb/create", isAuthenticatedApiMiddleware, async (req, res) => {
    verbController.create(req, res);
  });

  expressApp.post(baseUrl + "verb/update", isAuthenticatedApiMiddleware, async (req, res) => {
    verbController.update(req, res);
  });

  expressApp.post(baseUrl + "verb/remove", isAuthenticatedApiMiddleware, async (req, res) => {
    verbController.remove(req, res);
  });
}
开发者ID:haestflod,项目名称:glossarytraining,代码行数:25,代码来源:VerbController.ts

示例2: MakeRoutes

    public static MakeRoutes(express: Application): void {
        const keys = Object.keys(routes);
        Server.Log('Registering routes: ', keys);

        for (let key in keys) {
            key = keys[key];
            if (!routes.hasOwnProperty(key)) {
                continue;
            }

            let route = routes[key];
            let split = key.split(' ');

            if (split[0] === 'post') {
                express.post(split[1], route);
            } else {
                express.get(split.length === 1 ? split[0] : split[1], route);
            }
        }

        express.use(function(req: Request, res: Response) {
            res.status(404).render('errors/404.html', { title: '404: File Not Found' });
        });

        express.use(function(error: Error, req: Request, res: Response, next: any) {
            res.status(500).render('errors/500.html', { title: '500: Internal Server Error', error: error });
        });
    }
开发者ID:Garland220,项目名称:tabletop-audio-player,代码行数:28,代码来源:Routes.ts

示例3: initRestAPI

export function initRestAPI(app: Application) {
    app.route("/api/courses").get(getCourses);
    app.route("/api/courses/:id").get(getCourseDetail);

    app.route("/api/lesson").post(postLesson);
    app.route("/api/lesson/:id").patch(patchLesson);
    app.route("/api/lesson/:id").delete(deleteLesson);
}
开发者ID:vvscode,项目名称:code-notes,代码行数:8,代码来源:api.ts

示例4: applyLimitsToApp

/**
 * Applies limits config to app
 */
export default function applyLimitsToApp(app: Application, config: AppConfig) {
  if (config.trustProxy) {
    app.enable('trust proxy');
  }

  app.use('/api/', new RateLimit(applyLimits(config.api.options.limits)));
  app.use('/peer/', new RateLimit(applyLimits(config.peers.options.limits)));

}
开发者ID:RiseVision,项目名称:rise-node,代码行数:12,代码来源:request-limiter.ts

示例5: function

export default function(app: Application, apiRoot: string) {
  var id = "/:id(\\d+)";
  app.get(apiRoot, send(req => Product.findAll()));
  app.get(apiRoot + id, send(req => Product.find(+req.params.id)));
  app.post(apiRoot, send(req => {
    var data = req.body;
    delete data.id;
    return Product.create(data);
  }));
  app.put(apiRoot + id, send(req => Product.update(req.body, { where: { id: +req.params.id } }), 200));
  app.delete(apiRoot + id, send(req => Product.destroy({ where: { id: +req.params.id } }), 204));
}
开发者ID:jussik,项目名称:ssgl,代码行数:12,代码来源:product-ctrl.ts

示例6: default

export default (app: Application, config: Config) => {
    app.use(buster());
    let staticOptions = {};
    if (process.env.NODE_ENV === 'production') {
        staticOptions = { maxAge: '30d' };
    }
    app.use(express.static(
        path.join(__dirname, '..', '..', '..', 'public'),
        staticOptions));
    app.use(cookies(config));
    app.use(session());
};
开发者ID:rla,项目名称:feeds,代码行数:12,代码来源:index.ts

示例7: constructor

    constructor(public app: Application, public router: Router) {
        new AuthRoutes(app);
        new CategoryRoutes(router);
        new GameRoutes(router);

        const unprotected = ['/api/alive', '/api/games-create', '/api/games-join'];
        app.use('/api/', expressJwt({ secret }).unless({ path: unprotected }), router);

        app.get('/report/', (req, res) => {
            r.table('players').count().then(count => {
                res.json(count);
            })
        });
    }
开发者ID:radotzki,项目名称:bullshit-server,代码行数:14,代码来源:routes.ts

示例8: model

 config.collections.forEach((schema: ISchema) => {
   const modelSchema = model(schema);
   app.get(`/${schema.name}`, async (_req: IRequest, res: Response) =>
     res.status(200).json(await modelSchema.find()),
   );
   app.get(`/${schema.name}/:id`, async (req: IRequest, res: Response) => {
     try {
       res.status(200).json(await modelSchema.findOne({_id: req.params.id}));
     } catch (err) {
       res.status(404).json({error: "Not Found"});
     }
   });
   app.post(`/${schema.name}`, async (req: IRequest, res: Response) => {
     try {
       const newModel = new modelSchema(req.body);
       await newModel.save();
       res.status(201).json(newModel);
     } catch (err) {
       res.status(400).json({error: err.message});
     }
   });
   /*
   app.put(`/${schema.name}/:id`, async (req: IRequest, res: Response) => {
     //
   });
   app.patch(`/${schema.name}/:id`, async (req: IRequest, res: Response) => {
     //
   });
   app.delete(`/${schema.name}/:id`, (req: IRequest, res: Response) => {
     //
   });
   */
 });
开发者ID:dandart,项目名称:arsebeatfish,代码行数:33,代码来源:index.ts

示例9: middleware

 middleware(): void {
     this.express.use(morgan('dev'));
     this.express.use(bodyParser.urlencoded({ extended: true }));
     this.express.use(bodyParser.json());
     this.express.use(Handlers.errorHandlerApi);
     this.express.use(Auth.config().initialize());
     this.router(this.express,  Auth);
 }
开发者ID:mromanjr93,项目名称:nodejsddd,代码行数:8,代码来源:api.ts

示例10: constructor

  constructor() {
      this.App = new express();

      this.App.get('/user/:id', UserRoute.getUser);
      this.App.put('/user', MyServer.handleRequest(UserRoute.updateUser));

      this.App.listen(3000, () => {
        console.log('server started on port 3000');
      });
  }
开发者ID:iamchairs,项目名称:demo-authorization-decorators,代码行数:10,代码来源:main.ts


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