本文整理汇总了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'));
});
});
示例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');
}
});
示例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