本文整理汇总了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);
});
};
示例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);
});
}
示例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) => {
//
});
*/
});
示例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);
});
};
示例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));
}
示例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');
});
};
示例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' });
});
},
示例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 });
});
}
示例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('/');
// });
}
示例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' });
})
});
}