本文整理匯總了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"};
});
示例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',
示例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;
示例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 {