constructor( private readonly configService: ConfigService, private readonly logger: MyLoggerService, ) { this.compression = compression(); }
this[kBundlers] = enableWatchify ? [testBundler, clientBundler] : [] this[kApp] = express() this[kApp].use(compression())
app.use(compression());
server.use(compression()); server.use(express.json());
app.prepare().then(() => { const server = express(); server.use(compression({ threshold: 0 })); server.use( cors({
app.use(compression()); app.use(bodyParser.json());
/* Compression -----------------------------------------------*/ app.use(compression({ filter: function(req, res){ return req.headers["x-no-compression"] ? false : compression.filter(req, res); } }));
// Production middlewares const addProdMiddlewares = (app, options) => { 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'))); }
function makeApp(config, _log, createDb) { assert(typeof config === 'object'); assert(typeof _log === 'object'); assert(typeof _log.info === 'function'); assert(typeof createDb === 'function'); var app = express(), router = makeRouter(createDb); app.use(compression()); app.use(express.json()); app.use(function(req, res, next) { // XXX pass this into modules req.log = _log.child({req_id: uuid.v4()}); req.config = config; next(); }); app.use('/jobs/', router); return app; }
async runServer(){ cogear.loader.start('Starting server...'); cogear.server = express(); cogear.server.use(express.static(cogear.options.output)); cogear.server.use(compression()); cogear.server.use('/',expressStaticGzip(cogear.options.output)); await cogear.emit('server.init',cogear.server); cogear.server.on('error',(e)=>{ cogear.loader.fail(e); // console.info(e.stack) }); cogear.http = http.createServer(cogear.server).listen(cogear.config.port,cogear.config.host, async(err) => { if(err){ cogear.loader.fail(err); process.exit(); } await cogear.emit('server.listen',cogear.server); }); }
function CordovaServe () { this.app = express(); // Attach this before anything else to provide status output this.app.use((req, res, next) => { res.on('finish', function () { const color = this.statusCode === '404' ? chalk.red : chalk.green; let msg = `${color(this.statusCode)} ${this.req.originalUrl}`; const encoding = this._headers && this._headers['content-encoding']; if (encoding) { msg += chalk.gray(` (${encoding})`); } require('./server').log(msg); }); next(); }); // Turn on compression this.app.use(compression()); this.servePlatform = require('./platform'); this.launchServer = require('./server'); this.launchBrowser = require('./browser'); }
// Creates express app, adds express plugins, extends app async function createApp (config) { const app = express() app.use(cors()) app.use(compression()) config.mongoStore && await addMongoStore(config) app.use(expressSession(config.sessionParams)) app.use(createCookieParser(config)) app.use(bodyParser.json()) app.use(bodyParser.urlencoded({ extended: false })) config.static.directories.forEach((directory) => app.use( express.static(path.resolve(directory), config.static.config) )) console.log(`${logo} created express app instance`) return app }
const initMiddleware = (app) => { debug('Initializing middlewares...'); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(helmet()); app.use(cors()); app.use(logger('dev')); app.disable('x-powered-by'); app.use(compression()); // Initialize Passport app.use(passport.initialize()); app.use(passport.session()); debug('Finished initializing middlewares...'); }
server.use(compression()); server.use(express.json());
// Production middlewares const addProdMiddlewares = (app, options) => { 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'))); }