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