當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript helmet類代碼示例

本文整理匯總了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;未經允許,請勿轉載。