本文整理汇总了TypeScript中express-promise-router.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: require
import winston = require('winston');
import User from '@app/core/user/model/User';
import InvalidLocalPasswordError from '@app/core/user/error/InvalidLocalPasswordError';
import InvalidLocalIdError from '@app/core/user/error/InvalidLocalIdError';
import UserCredentialService = require('@app/core/user/UserCredentialService');
import UserService = require('@app/core/user/UserService');
import UserDeviceService = require('@app/core/user/UserDeviceService');
import AlreadyRegisteredFbIdError from '@app/core/user/error/AlreadyRegisteredFbIdError';
import DuplicateLocalIdError from '@app/core/user/error/DuplicateLocalIdError';
import RequestContext from '../model/RequestContext';
import ErrorCode from '../enum/ErrorCode';
import { restGet, restPut } from '../decorator/RestDecorator';
import UserAuthorizeMiddleware from '../middleware/UserAuthorizeMiddleware';
var logger = winston.loggers.get('default');
var router = ExpressPromiseRouter();
router.use(UserAuthorizeMiddleware);
restGet(router, '/info')(async function (context, req) {
let user:User = context.user;
return UserService.getUserInfo(user);
});
restPut(router, '/info')(async function (context, req) {
let user:User = context.user;
if (req.body.email) {
await UserService.setUserInfo(user, req.body.email);
}
return {message:"ok"};
});
开发者ID:wafflestudio,项目名称:snutt,代码行数:31,代码来源:UserRouter.ts
示例2: PromiseRouter
import * as express from 'express';
import * as uuid from 'uuid';
import PromiseRouter from 'express-promise-router';
const router = PromiseRouter();
router.get('/', async (req: express.Request, res: express.Response) => {
const id = uuid.v4();
const timer = setInterval(() => {
res.write('event:keepalive\ndata:\n\n');
}, 30000);
req.socket.setKeepAlive(true);
req.socket.setTimeout(0);
req.connection.on('close', () => {
clearInterval(timer);
delete req.app.locals.pushClients[id];
res.end();
});
req.app.locals.pushClients[id] = res;
// The no-transform value of the Cache-Control header tells the
// compresssion middleware not to compress this
// response. Otherwise, the client never sees any of the writes.
res.writeHead(200, {
'Cache-Control': 'no-cache, no-transform',
'Connection': 'keep-alive',
'Content-Type': 'text/event-stream',
开发者ID:lovett,项目名称:notifier,代码行数:31,代码来源:push.ts
示例3: require
* Lists and revokes oauth client authorizations
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
'use strict';
import * as express from 'express';
const PromiseRouter = require('express-promise-router');
import OAuthClients from '../models/oauthclients';
import {ClientRegistry} from '../oauth-types';
const OAuthClientsController = PromiseRouter();
/**
* Get the currently authorized clients
*/
OAuthClientsController.get('/', async (request: express.Request, response: express.Response) => {
let user = (request as any).jwt.user;
let clients = await OAuthClients.getAuthorized(user);
response.json(clients.map((client: ClientRegistry) => {
return client.getDescription();
}));
});
OAuthClientsController.delete('/:clientId', async (request: express.Request, response: express.Response) => {
let clientId = request.params.clientId;
开发者ID:jdiazmx,项目名称:gateway,代码行数:31,代码来源:oauthclients_controller.ts
示例4: require
const knexConfig = require('../knexfile');
const promiseRouter = require('express-promise-router');
// Initialize knex.
export const knex = Knex(knexConfig.development);
// Create or migrate:
knex.migrate.latest();
// Bind all Models to a knex instance. If you only have one database in
// your server this is all you have to do. For multi database systems, see
// the Model.bindKnex method.
Model.knex(knex);
const router: express.Router = promiseRouter();
const app: express.Application = express()
.use(bodyParser.json())
.use(morgan('dev'))
.use(router)
.set('json spaces', 2);
// Register our REST API.
registerApi(router);
// Error handling. The `ValidationError` instances thrown by objection.js have a `statusCode`
// property that is sent as the status code of the response.
app.use((err: any, req: express.Request, res: express.Response,next: express.NextFunction) => {
if (err) {
res.status(err.statusCode || err.status || 500).send(err.data || err.message || {});
} else {
开发者ID:johannessjoberg,项目名称:objection.js,代码行数:30,代码来源:app.ts
注:本文中的express-promise-router.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论