• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript compression类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中compression的典型用法代码示例。如果您正苦于以下问题:TypeScript compression类的具体用法?TypeScript compression怎么用?TypeScript compression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了compression类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: function

export default function(config: IAppConfig): IServer {
	let app = express();

	// Make the public folder available
	app.use(express.static(path.resolve(__dirname, '..', 'public')));
	app.use('/shared', express.static(path.resolve(__dirname, '..', 'shared')));

	if (process.env.NODE_ENV === 'local' || process.env.NODE_ENV === 'local-development') {
		// console.log(path.resolve(__dirname, '..', '..', 'src'));
		app.use('/src', express.static(path.resolve(__dirname, '..', '..', 'src')));
		// Make all client files available for dev
		app.use('/node_modules', express.static('node_modules'));
	}

	// Request body parsing middleware should be above methodOverride
	// app.use(bodyParser.urlencoded({
	// 	extended: true
	// }));
	app.use(timeout('30s'));
	// app.use(bodyParser.json());
	// app.use(cookieParser());
	app.use(compression());

	const server = app.listen(config.port, () => {
		console.log("Listening on port", config.port);
	});

	return { express: app, http: server };
}
开发者ID:bfsmith,项目名称:desktop-chat,代码行数:29,代码来源:express.ts


示例2: newInstance

    newInstance(config: IConfig, env: string): express.Express {
        var app = express();

        app.set("views", config.root + "/server/views");
        app.set("view engine", "html");
        app.use(compression());
        app.use(bodyParser.urlencoded({ extended: false }));
        app.use(bodyParser.json());
        app.use(methodOverride());
        app.use(cookieParser());

        // Persist sessions with mongoStore / sequelizeStore
        // We need to enable sessions for passport-twitter because it"s an
        // oauth 1.0 strategy, and Lusca depends on sessions
        /*app.use(session({
            secret: config.secrets.session,
            saveUninitialized: true,
            resave: false,
            store: new mongoStore({
                mongooseConnection: mongoose.connection,
                db: "opcrates-bot-server"
            })
        }));*/

        app.set("appPath", path.join(config.root, "client"));
        app.use(morgan("dev"));
        app.use(express.static(app.get("appPath")));

        if ("development" === env || "test" === env) {
            app.use(express.static(path.join(config.root, ".tmp")));
            app.use(errorHandler()); // Error handler - has to be last
        }

        return app;
    }
开发者ID:Tmeister,项目名称:generator-typescript-express,代码行数:35,代码来源:applicationFactory.ts


示例3: function

export default function(app) {
  let env = app.get('env');

  app.set('views', config.root + '/server/views');
  app.set('view engine', 'jade');
  app.use(compression());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  app.use(methodOverride());
  app.use(cookieParser());
  app.use(passport.initialize());

  app.set('appPath', path.join(config.root, 'client'));

  if ('production' === env) {
    app.use(favicon(path.join(config.root, 'client', 'favicon.ico')));
    app.use(express.static(app.get('appPath')));
    app.use(morgan('dev'));
  }

  if ('development' === env) {
    app.use(require('connect-livereload')());
  }

  if ('development' === env || 'test' === env) {
    app.use(express.static(path.join(config.root, '.tmp')));
    app.use(express.static(app.get('appPath')));
    app.use(morgan('dev'));
    app.use(errorHandler()); // Error handler - has to be last
  }
}
开发者ID:Jeremy-Doucet,项目名称:Blog-Example-Typescript,代码行数:31,代码来源:express.ts


示例4: load

    @InitPhase
    @Inject(['logger', 'express'])
    load(logger, app) {
        logger.debug('load compression');

        app.use(compression());
    }
开发者ID:HallM,项目名称:poc-fw2,代码行数:7,代码来源:index.ts


示例5: 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


示例6: setup

	public setup() {
		this.logger.debug("Enabling GZip compression.");

        this.app.use(expressCompression({
            threshold: 512,
        }));

		this.logger.debug("GZip compression enabled.");
	}
开发者ID:Event-Starter-Kit,项目名称:website,代码行数:9,代码来源:001.compression.ts


示例7: express

export const expressConfig = (): core.Express => {
  const app: core.Express = express();
  app.use(bodyParser.json({ limit: '50mb' }));
  app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'assets')));
  app.use(cors());
  app.use(compression({filter: shouldCompress}));

  return app;
};
开发者ID:Cyphle,项目名称:Portfolio,代码行数:11,代码来源:express.config.ts


示例8:

const addProdMiddlewares = (app: Express.Application, options: IOptions) => {
  const publicPath = options.publicPath || '/';
  const outputPath = options.outputPath || Path.resolve(process.cwd(), 'build');

  // compression middleware compresses your server responses which makes them
  // smaller (applies also to assets). You can read more about that technique
  // and other good practices on official Express.js docs http://mxs.is/googmy
  app.use(Compression());
  app.use(publicPath, Express.static(outputPath));

  app.get('*', (req, res) => res.sendFile(Path.resolve(outputPath, 'index.html')));
};
开发者ID:StrikeForceZero,项目名称:react-boilerplate,代码行数:12,代码来源:frontendMiddleware.ts


示例9: preconfigExpress

export function preconfigExpress() {
  var app = express();

  if (config.ENV === 'prod') {
    app.use(compress());
  } else {
    app.use(morgan('dev'));
  }

  app.use(bodyParser.urlencoded({
    extended: true
  }));
  app.use(bodyParser.json());
  app.use(methodOverride());

  // app.use(session({
  //   saveUninitialized: true,
  //   resave: true,
  //   secret: config.SESSION_SECRET
  // }));

  // app.set('views', normalize(join(__dirname, 'src/core/server/views')));
  // app.set('view engine', 'ejs');

  route.routes(app);

  app.use(express.static(normalize(__dirname)));

  return app;
}
开发者ID:baodongliu,项目名称:mea2nt,代码行数:30,代码来源:express.ts


示例10: createJSONServer

export function createJSONServer(port: number, queryProcessor: JSONQueryProcessor): void {
  var app = express();
  app.disable('x-powered-by');

  app.use(compress());

  app.get('/health', (req: Request, res: Response) => {
    res.send(`I am healthy @ ${new Date().toISOString()}`);
  });

  app.use(bodyParser.json());
  app.post('/plyql', (req: Request, res: Response) => {
    var { sql } = req.body;

    if (typeof sql !== "string") {
      res.status(400).json({ error: "'sql' must be a string" });
      return;
    }

    console.log(`Got SQL: ${sql}`);
    queryProcessor({ sql }, res);
  });

  app.use((err: any, req: Request, res: Response, next: Function) => {
    res.status(err.status || 500);
    res.json({ error: err.message });
  });

  var server = http.createServer(app);

  server.on('error', (error: any) => {
    if (error.syscall !== 'listen') {
      throw error;
    }

    // handle specific listen errors with friendly messages
    switch (error.code) {
      case 'EACCES':
        console.error(`Port ${port} requires elevated privileges`);
        process.exit(1);
        break;

      case 'EADDRINUSE':
        console.error(`Port ${port} is already in use`);
        process.exit(1);
        break;

      default:
        throw error;
    }
  });

  server.on('listening', () => {
    var address = server.address();
    console.log('PlyQL server listening on port: ' + address.port);
  });

  app.set('port', port);
  server.listen(port);
}
开发者ID:waltonseymour,项目名称:plyql,代码行数:60,代码来源:json-server.ts



注:本文中的compression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript concaveman类代码示例发布时间:2022-05-28
下一篇:
TypeScript compare-versions类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap