本文整理汇总了TypeScript中helmet类的典型用法代码示例。如果您正苦于以下问题:TypeScript helmet类的具体用法?TypeScript helmet怎么用?TypeScript helmet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了helmet类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: config
/**
* Configures application
*
* @class Server
* @method config
* @return {void}
*/
public config(): void {
// mount query string parser
this.app.use(bodyParser.urlencoded({
extended: true
}))
// mount json form parser
this.app.use(bodyParser.json())
// mount cookie parker
this.app.use(cookieParser())
// mount logger
this.app.use(logger("dev"))
// mount compression
this.app.use(compression())
// mount helmet
this.app.use(helmet())
// mount cors
this.app.use(cors())
// cors
// this.app.use((req: Request, res: Response, next: NextFunction) => {
// res.header('Access-Control-Allow-Origin', 'http://localhost:8080')
// res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS, PURGE')
// res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, Access-Control-Allow-Credentials')
// res.header('Access-Control-Allow-Credentials', 'true')
// next()
// })
}
开发者ID:yeegr,项目名称:SingularJS,代码行数:40,代码来源:server.ts
示例2:
server.setConfig((app) => {
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(helmet());
});
开发者ID:inversify,项目名称:inversify-express-example,代码行数:7,代码来源:bootstrap.ts
示例3: Promise
return new Promise((resolve, reject) => {
// we need to verify if we have a repository added and a server port
if (!options.repo) {
reject(new Error('The server must be started with a connected repository'))
}
if (!options.port) {
reject(new Error('The server must be started with an available port'))
}
// let's init a express app, and add some middlewares
const app = express();
const http = _http.createServer(app);
app.use(morgan('dev'));
app.use(helmet());
app.use((err, req, res, next) => {
reject(new Error('Something went wrong!, err:' + err));
res.status(500).send('Something went wrong!')
});
// we add our API's to the express app
traderChannelsAPI(app, options);
// finally we start the server, and return the newly created server
const server = app.listen(options.port, () => resolve(server))
})
开发者ID:Chegeek,项目名称:TradeJS,代码行数:26,代码来源:server.ts
示例4: init
static init(application:Object, exp:Object):void {
let _clientFiles = (process.env.NODE_ENV === 'production') ? '/client/dist/' : '/client/dev/';
let _root = process.cwd();
application.use(exp.static(_root));
application.use(exp.static(_root + _clientFiles));
application.use(bodyParser.json());
application.use(morgan('dev'));
application.use(helmet());
}
开发者ID:suvetig,项目名称:ppt,代码行数:10,代码来源:routes.conf.ts
示例5: init
static init(application: express.Application):void {
let _root = process.cwd();
let _nodeModules = '/node_modules/';
let _clientFiles = (process.env.NODE_ENV === 'production') ? '/client/dist/' : '/client/dev/';
application.use(express.static(_root + _nodeModules));
application.use(express.static(_root + _clientFiles));
application.use(bodyParser.json());
application.use(morgan('dev'));
application.use(helmet());
}
开发者ID:Abdizriel,项目名称:generator-ng-fullstack,代码行数:11,代码来源:routes.conf.ts
示例6: init
static init(application: express.Application, exp: express.Express):void {
let _clientFiles = (process.env.NODE_ENV === 'production') ? '/client/dist/' : '/client/dev/';
let _root = process.cwd();
application.use(exp.static(_root));
application.use(exp.static(_root + _clientFiles));
application.use(bodyParser.json());
application.use(morgan('dev'));
application.use(contentLength.validateMax({max: 999}));
application.use(helmet());
}
开发者ID:Kablex,项目名称:generator-ng-fullstack,代码行数:11,代码来源:routes.conf.ts
示例7: enableFor
enableFor (app: express.Express) {
app.use(helmet())
app.use(/^\/(?!js|img|pdf|stylesheets).*$/, helmet.noCache())
new ContentSecurityPolicy(this.developmentMode).enableFor(app)
if (this.config.referrerPolicy) {
new ReferrerPolicy(this.config.referrerPolicy).enableFor(app)
}
if (this.config.hpkp) {
new HttpPublicKeyPinning(this.config.hpkp).enableFor(app)
}
}
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:14,代码来源:index.ts
示例8:
server.setConfig((exApp) => {
exApp.use(cookieParser());
exApp.use(bodyParser.json());
exApp.use(bodyParser.urlencoded({extended: true}));
exApp.use(helmet());
exApp.use(session({
resave: false,
saveUninitialized: true,
secret: 'testing',
}));
exApp.use(passport.initialize());
exApp.use(passport.session()); // persistent login sessions
});
开发者ID:Uter1007,项目名称:sumobase.core,代码行数:15,代码来源:app.fake.ts
示例9: init
static init(application: express.Application):void {
let _root = process.cwd();
let _nodeModules = '/node_modules/';
let _clientFiles = (process.env.NODE_ENV === 'production') ? '/client/dist/' : '/client/dev/';
application.use(compression({
level: zlib.Z_BEST_COMPRESSION,
threshold: '1kb'
}));
application.use(express.static(_root + _nodeModules));
application.use(express.static(_root + _clientFiles));
application.use(bodyParser.json());
application.use(morgan('dev'));
application.use(helmet());
}
开发者ID:Necromant1k,项目名称:BarbershopOnline,代码行数:16,代码来源:routes.conf.ts
示例10: createServer
export default function createServer(opts : IOptions) : express.Application {
const app = express();
app.use(helmet({
hsts: {
maxAge: 5184000,
setIf: () => !opts.allowHttp,
includeSubdomains: false
},
noCache: true,
expectCt: {
enforce: false,
maxAge: 1000
}
}));
app.use(referrerPolicy({ policy: 'same-origin' }));
if (process.env.NODE_ENV !== 'test') {
app.use(morgan('combined'));
}
if (opts.allowed_ips.length) {
app.set('trust proxy', true);
app.use(AccessControl({
mode: 'allow',
allows: opts.allowed_ips,
statusCode: 404
}));
}
if (opts.basicAuth.length) {
app.use(basicAuthHandler(opts.basicAuth[0], opts.basicAuth[1]));
}
if (opts.dirList) {
app.use(serveIndexHandle(opts.serveDir));
} else {
app.use(indexHandle);
}
app.use(staticFileHandle(opts.serveDir));
app.use(handle404(opts.serveDir));
app.use(compression({ level: 9 }));
return app;
}
开发者ID:RealOrangeOne,项目名称:host-container,代码行数:47,代码来源:server.ts
注:本文中的helmet类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论