本文整理汇总了TypeScript中swagger-express-mw.create函数的典型用法代码示例。如果您正苦于以下问题:TypeScript create函数的具体用法?TypeScript create怎么用?TypeScript create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: require
'use strict';
import express = require('express');
let saggerExpress = require('swagger-express-mw');
let swaggerUi = require('swagger-tools/middleware/swagger-ui');
let app: express.Application = express();
let bodyParser = require('body-parser');
import config = require('./config/config');
import db = require('./api/db/index');
module.exports = app; // for testing
app.use(bodyParser.json());
db.connect();
require('./api/models/index');
saggerExpress.create({appRoot: __dirname}, (err: any, se: any) => {
if (err) { throw err; }
app.use(swaggerUi(se.runner.swagger));
// install middleware
se.register(app);
app.listen(config.get('server.port'), () => {
console.log('Server listening to localhost:' + config.get('server.port'));
});
});
开发者ID:vmishevski,项目名称:quiz-node,代码行数:29,代码来源:app.ts
示例2: function
swaggerExpress.create(swaggerConfig, function (err, swagger) {
if (err) { throw err; }
app.use(function (req, res, next) {
next();
});
app.use(cors(corsOptions));
swagger.register(app);
app.get(
'/auth/google',
passport.authenticate('google', {
session: false,
scope: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email',
],
}),
);
app.get('/auth/google/callback',
function (req, res, next) {
passport.authenticate('google', {
session: false,
failureRedirect: api.helpers.Config.settings.ui_base_path,
},
function (error, user: api.models.UserModel, info) {
if (error) { return next(error); }
if (!user) { return res.redirect(api.helpers.Config.settings.ui_base_path); }
try {
let token = jwtService.signToken(user);
// to prevent from csrf attack we sent back a XSRF-TOKEN in a cookie
res.cookie('XSRF-TOKEN', token.xsrf, { maxAge: 900000, httpOnly: false });
res.cookie('JWT-TOKEN', token.jwt, { maxAge: 900000, httpOnly: true });
let isAdmin = 'false';
if (user.roles && user.roles.indexOf('admin') > -1) {
isAdmin = 'true';
}
return res.redirect(`${api.helpers.Config.settings.ui_base_path}/#/login?user_id=${user.id}&is_admin=${isAdmin}`);
} catch (err) {
return next(err);
}
})(req, res, next);
});
app.listen(port);
if (swagger.runner.swagger.paths['/hello']) {
console.log('try this:\ncurl http://127.0.0.1:' + port + '/hello?name=Scott');
}
});
开发者ID:arandehkharghani,项目名称:tforex-gateway,代码行数:53,代码来源:app.ts
示例3: require
import * as SwaggerExpress from "swagger-express-mw";
import express = require("express");
const app = express();
const config: SwaggerExpress.Config = {
appRoot: __dirname
};
SwaggerExpress.create(config, (err, middleware) => {
if (err) {
throw err; // or handle error
}
middleware.register(app);
const port = process.env.PORT || 10010;
app.listen(port);
});
const swaggerSecurityHandlerCb = (err: Error) => {
// do nothing
};
const configComplex: SwaggerExpress.Config = {
appRoot: __dirname,
configDir: "some/directory",
controllersDirs: ["some/directory"],
fittingsDirs: ["some/directory"],
mockMode: true,
swaggerControllerPipe: 'swagger_controllers',
swaggerSecurityHandlers: {
// did not manage to research the typings of first 3 arguments
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:31,代码来源:swagger-express-mw-tests.ts
注:本文中的swagger-express-mw.create函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论