本文整理汇总了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()
// })
}
示例2:
server.setConfig((app) => {
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(helmet());
});
示例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))
})
示例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());
}
示例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());
}
示例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());
}
示例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)
}
}
示例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
});
示例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());
}
示例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;
}