當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Application.get方法代碼示例

本文整理匯總了TypeScript中express.Application.get方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Application.get方法的具體用法?TypeScript Application.get怎麽用?TypeScript Application.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在express.Application的用法示例。


在下文中一共展示了Application.get方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

export var setupPhraseRoutes = function (baseUrl: string, expressApp: Application) {
  const categoryHandler = new CategoryHandler();
  const phraseHandler = new PhraseHandler(categoryHandler);

  const phraseController = new PhraseController(phraseHandler);

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

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

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

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

  expressApp.post(baseUrl + "phrase/remove", isAuthenticatedApiMiddleware, async (req, res) => {
    phraseController.removePhrase(req, res);
  });

  expressApp.get(baseUrl + "phrase/category/:id", async (req, res) => {
    phraseController.getPhrasesForCategory(req, res);
  });
};
開發者ID:haestflod,項目名稱:glossarytraining,代碼行數:30,代碼來源:PhraseController.ts

示例2: 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

示例3: 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

示例4: function

export var setupCategoryRoutes = function (baseUrl: string, expressApp: Application) {
  const categoryHandler = new CategoryHandler();

  const categoryController = new CategoryController(categoryHandler);

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

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

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

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

  expressApp.post(baseUrl + "category/remove", isAuthenticatedApiMiddleware, async (req, res) => {
    categoryController.remove(req, res);
  });

  expressApp.get(baseUrl + "category/hasphrases", async (req, res) => {
    categoryController.allHasPhrases(req, res);
  });
};
開發者ID:haestflod,項目名稱:glossarytraining,代碼行數:29,代碼來源:CategoryController.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

/**
 * Sets up route handlers for static HTML pages.
 */
export default (app: Application, config: Config) => {

    app.get('/', (req, res) => {
        res.render('index', {
            loggedIn: (req as AppRequest).isAuthenticated(),
            version: config.version,
            title: config.title || 'Feeds',
            production: process.env.NODE_ENV === 'production'
        });
    });

    app.get('/old', (req, res) => {
        res.render('old');
    });
};
開發者ID:rla,項目名稱:feeds,代碼行數:18,代碼來源:front.ts

示例7:

 setup: (app: Application, server: WebpackDevServer) => {
     // Here you can access the Express app object and add your own custom middleware to it.
     // For example, to define custom handlers for some paths:
     app.get('/some/path', (req, res) => {
         res.json({ custom: 'response' });
     });
 },
開發者ID:csrakowski,項目名稱:DefinitelyTyped,代碼行數:7,代碼來源:webpack-dev-server-tests.ts

示例8: 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

示例9: config

  config(app: Application, passport: Passport){
    app.get("/", function(req: Request, res: Response){
      res.sendFile("index.html", {"root": "pages/"});
    });

    app.get("/ping", passport.authenticate("bearer", { session: false }), this.serialize, this.generateToken, function(req: Request, res: Response){
      res.status(200).json({hello: "world"});
    });

    app.get("/google", passport.authenticate("google", { session: false }), function(req: Request, res: Response){
      res.status(200).json({google: "success"});
    });

    // app.get("/login", function(req: Request, res: Response){
    //   res.sendFile("login.html", {"root": "pages/"});
    // });

    // app.get("/signup", function(req: Request, res: Response){
    //   res.sendFile("signup.html", {"root": "pages/"});
    // });

    // app.get("/finance", function(req: Request, res: Response){
    //   res.sendFile("finance.html", {"root": "pages/"});
    // });

    // app.post('/login', passport.authenticate('local-login', {
    //   successRedirect : '/finance', // redirect to the secure profile section
    //   failureRedirect : '/login', // redirect back to the signup page if there is an error
    //   failureFlash : true // allow flash messages
    // }));

    // // process the signup form
    // app.post('/signup', passport.authenticate('local-signup', {
    //   successRedirect : '/finance', // redirect to the secure profile section
    //   failureRedirect : '/signup', // redirect back to the signup page if there is an error
    //   failureFlash : true // allow flash messages
    // }));

    // // =====================================
    // // LOGOUT ==============================
    // // =====================================
    // app.get('/logout', function(req, res) {
    //   req.logout();
    //   res.redirect('/');
    // });
  }
開發者ID:kongbb,項目名稱:MyFinance,代碼行數:46,代碼來源:index.route.ts

示例10: setupApiRoutes

function setupApiRoutes(app: Application){
	app.get('/api/boards', function(req:Request, res:Response){
		tokenGuard(req).then(function(token:any){
			return getBoards(token.id)
		}).then(function (boards:IBoard[]){
			res.json({ success:true, message:'', boards: boards });
		})
		.catch( function(error:string){
			env().logger().error(error);
			res.json({ success:false, message:'failed to get boards' });
		})
	});  
	
	/*
	app.get('/api/recent', function(req:Request, res:Response){
		apiGuard(req,res, function(req:Request, res:Response, token:any){
			getRecent(token.id, function(success:boolean, message:string, boards?:IBoard[]) {
				res.json({ success:true, message:'', boards: boards });
			})	
		}
	});*/

	app.get('/api/board/:id', function(req:Request, res:Response){
		//TODO CHECK IF USER HAS ACCESS TO THIS SECTIONS
		tokenGuard(req)
		.then( function(decodedToken:any){
			
			var p1 = getSections(decodedToken.id, req.params.id);
			var p2 = getBoard(decodedToken.id, req.params.id);
			let p : [Promise<ISection[]>,Promise<IBoard>] = [p1,p2];
			
			return Promise.all(p);
			//return getSections(decodedToken.id, req.params.id) 
		})
		.then( function(results:any){
			var sections:ISection[]= results[0]
			var board:IBoard = results[1]
			res.json({ success:true, board:board, sections: sections });
		})
		.catch( function(error:string){
			env().logger().error(error);
			res.json({ success:false, message:'failed to get board' });
		})
	});  

}
開發者ID:ychebotarev,項目名稱:InColUn-v0,代碼行數:46,代碼來源:api.ts


注:本文中的express.Application.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。