本文整理汇总了TypeScript中express.Router.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Router.get方法的具体用法?TypeScript Router.get怎么用?TypeScript Router.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类express.Router
的用法示例。
在下文中一共展示了Router.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createRoutes
export function createRoutes(router: Router, auth: RequestHandler, setRouteVar: RequestHandler): void {
// list route
router.get('/', setRouteVar, list)
// single entry route
router.get('/:slug', setRouteVar, get)
// comment route
router.get('/:slug/comments', setRouteVar, comments)
// action list route
router.get('/:slug/:sublist', setRouteVar, sublist)
// check if slug available
router.post('/unique', setRouteVar, isUnique)
// create route
router.post('/', auth, setRouteVar, create)
// create gallery
router.put('/:slug/gallery', auth, setRouteVar, upload)
// clear gallery
router.delete('/:slug/gallery', auth, setRouteVar, clear, update)
// update route
router.patch('/:slug', auth, setRouteVar, update)
// delete route
router.delete('/:slug', auth, setRouteVar, remove)
}
示例2: Router
export const product = ({ db }: { db: any }) => {
const api: Router = Router();
/**
* Tokens are sold in packages - we store them as products
* This function returns all products
*/
api.get('/all', async (req: Request, res: Response) => {
try {
res.send(await findAll<Product>(DB_PRODUCTS));
} catch (err) {
res.status(409).json(err);
}
});
/**
* Coinbase orders can be looked up by the token address so problems
* can be identified
*/
api.get('/purchase-lookup-coinbase/:tokenRecipientAddress', vPurchaseLookup, async (req: Request, res: Response) => {
try {
res.send(await coinbaseLookup(req.params[KEY_TOKEN_RECIPIENT_ADDRESS]));
} catch (err) {
res.status(409).json({error: 'No data found for this Address'});
}
});
return api;
};
示例3: setupRoutes
setupRoutes() {
this.router.get(
'/pending',
this._checkTokenHeader,
this._needPermissions('read', 'bot.ghost_content'),
async (req, res) => {
res.send(await this.ghost.forBot(req.params.botId).getPending())
}
)
this.router.get(
'/export',
this._checkTokenHeader,
this._needPermissions('read', 'bot.ghost_content'),
async (req, res) => {
const tarball = await this.ghost.forBot(req.params.botId).exportArchive()
const name = 'archive_' + req.params.botId.replace(/\W/gi, '') + '_' + Date.now() + '.tgz'
res.writeHead(200, {
'Content-Type': 'application/tar+gzip',
'Content-Disposition': `attachment; filename=${name}`,
'Content-Length': tarball.length
})
res.end(tarball)
}
)
const archiveUploadMulter = multer({
limits: {
fileSize: 1024 * 1000 * 100 // 100mb
}
})
// TODO WIP Partial progress towards importing tarballs from the UI
// this.router.get(
// '/import',
// this.checkTokenHeader,
// this.needPermissions('write', 'bot.ghost_content'),
// archiveUploadMulter.single('file'),
// async (req, res) => {
// const buffer = req['file'].buffer
// const botId = req.params.botId
// await this.ghost.forBot(botId).importArchive(buffer)
// res.sendStatus(200)
// }
// )
// Revision ID
this.router.post(
'/revert',
this._checkTokenHeader,
this._needPermissions('write', 'bot.ghost_content'),
async (req, res) => {
const revisionId = req.body.revision
const filePath = req.body.filePath
await this.ghost.forBot(req.params.botId).revertFileRevision(filePath, revisionId)
res.sendStatus(200)
}
)
}
示例4: constructor
constructor(){
this.router = Router();
this.controller = new StockController();
this.router.get("/soldtrades", (req: Request, res: Response) => this.getSoldTrades(req, res));
this.router.get("/holdingstocks", (req: Request, res: Response) => this.getHoldingStocks(req, res));
this.router.post("/", upload.single('file'), (req: Request, res: Response) => this.uploadStockTransactionsCSV(req, res));
this.router.post("/import", (req: Request, res: Response) => this.importStockTransactions(req, res));
}
示例5: constructor
constructor(){
this.router = Router();
this.controller = new TransactionController();
this.router.get("/:type", (req: Request, res: Response) => this.getTransactions(req, res));
this.router.get("/:type/categories", (req: Request, res: Response) => this.getCategories(req, res));
this.router.post("/transaction", (req: Request, res: Response) => this.postTransaction(req, res));
this.router.post("/", upload.single('file'), (req: Request, res: Response) => this.uploadTransactionsCSV(req, res));
this.router.delete("/:id", (req: Request, res: Response) => this.deleteTransaction(req, res));
}
示例6: createRoutes
export function createRoutes(router: Router, setRouteVar: RequestHandler, auth: RequestHandler): void {
// list route
router.get('/users', setRouteVar, list)
// route to check unique values
router.post('/users/unique', setRouteVar, isUnique)
// create route
router.post('/users', setRouteVar, create)
// TOTP login route - create
router.post('/login/totp', setRouteVar, initTotp, sendTotp)
// TOTP login route - login/signup
router.patch('/login/totp', setRouteVar, verifyTotp, login)
// reset password routes via TOTP
router.patch('/login/reset', setRouteVar, verifyPasswords, verifyTotp)
// update routes via TOTP
router.patch('/self/totp', setRouteVar, auth, verifyTotp)
// login routes via username/passport
router.post('/login/local', setRouteVar, local, login)
// JWT login routes
router.get('/self', auth, login)
// sublist route
router.get('/self/:sublist', auth, sublist)
// user created content route
router.get('/self/:sublist/:slug', auth, content)
// update route
router.patch('/self', auth, update)
// update user avatar
router.put('/self/avatar', setRouteVar, auth, avatar)
// delete route
router.delete('/self', auth, remove)
// user submit content route
router.post('/self/submit', auth, submit)
// user retract content route
router.post('/self/retract', auth, retract)
}
示例7: default
export default () => {
const feedRoutes: Router = Router();
feedRoutes.get(
"/feed.xml",
async (req: Request, res: Response): Promise<void> => {
const templateData = getTemplateData({
title: "",
action: "/",
});
const posts: any[] = await getPosts();
return res
.set({
"Content-Type": "application/xml; charset=utf-8",
"Cache-Control": `max-age=${60 * 60 * 24}`,
})
.render("feed", {
layout: false,
...templateData,
posts,
});
},
);
return feedRoutes;
};
示例8: 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);
}
示例9: gameRouter
export function gameRouter(gameHandler: GameHandlerService): Router {
let router: Router = Router();
router.post('/',
[
body('title_ko').isString().not().isEmpty(),
body('title_en').isString().not().isEmpty(),
body('players').isArray(),
body('players.*').isInt().toInt(),
body('box.width').isInt().toInt(),
body('box.height').isInt().toInt(),
body('box.depth').isInt().toInt(),
body('setting.width').isInt().toInt(),
body('setting.height').isInt().toInt(),
],
handleValidationResult,
gameHandler.createGame.bind(gameHandler)
);
router.get('/:gid',
[param('gid').isNumeric().not().isEmpty()],
handleValidationResult,
gameHandler.getGame.bind(gameHandler)
);
return router;
}
示例10: config
public static config(router: Router): void {
// middleware that is specific to this router -- CORS
router.use((req: Request, res: Response, next: any)=> {
util.log(util.format("Request to: %s:%s -- Params:%s",
req.url, req.method, JSON.stringify(req.body)));
res.setHeader('Access-Control-Allow-Credentials', "true");
res.header("Access-Control-Allow-Origin", req.header("Origin"));
res.header("Access-Control-Allow-Methods", "GET,POST,PUT,HEAD,DELETE,OPTIONS");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
if ('OPTIONS' == req.method) {
res.sendStatus(200);
}
else {
next();
}
});
var APP_ROUTER: Router = Router();
// define routes
APP_ROUTER.get("/", (req, res)=> {
res.send('Twicepixels on-line');
});
router.use("/", APP_ROUTER);
router.use("/auth", AUTH_ROUTER);
router.use("/utils", UTIL_ROUTER);
router.use("/users", USER_ROUTER);
router.use("/accounts", ACCOUNT_ROUTER);
//billing routers
router.use("/billing", BILLING_ROUTER);
//collaborator routers
router.use("/collaborator", COLLABORATOR_ROUTER);
}