How to use express-static-gzip - 10 common examples

To help you get started, we’ve selected a few express-static-gzip examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github narendrashetty / uber-mobile-web / src / server.js View on Github external
import { match, RouterContext } from 'react-router';
import expressStaticGzip from 'express-static-gzip';
import device from 'express-device';

import createMemoryHistory from 'history/lib/createMemoryHistory';
import configureStore from './store';
import routes from './routes';

const server = Express();
const port = process.env.PORT || 3000;

server.use('/manifest.json', Express.static('./dist/manifest.json'));
server.use('/favicon.ico', Express.static('./dist/static/images/favicon.ico'));

server.use('/sw.js',  Express.static('./dist/sw.js'));
server.use('/static', expressStaticGzip('./dist/static', {
  'maxAge': 31536000,
  setHeaders: function(res, path, stat) {
    res.setHeader("Expires", new Date(Date.now() + 2592000000).toUTCString());
    return res;
  }
}));

/* At the top, with other redirect methods before other routes */
server.get('*',function(req,res,next){
  if(req.headers['x-forwarded-proto']!='https')
    res.redirect('https://' + req.hostname + req.url);
  else
    next(); /* Continue to other routes if we're not redirecting */
});

server.use(device.capture());
github Atomic-Reactor / Reactium / .core / index.js View on Github external
middlewares.push({
        name: 'hmr',
        use: wpHotMiddlware(compiler, {
            reload: true,
        }),
        order: Enums.priority.high,
    });
}

// serve the static files out of ./public or specified directory
const staticAssets =
    process.env.PUBLIC_DIRECTORY || path.resolve(process.cwd(), 'public');

middlewares.push({
    name: 'static',
    use: staticGzip(staticAssets),
    order: Enums.priority.neutral,
});

// default route handler
middlewares.push({
    name: 'router',
    use: router,
    order: Enums.priority.neutral,
});

// Give app an opportunity to change middlewares
if (fs.existsSync(`${rootPath}/src/app/server/middleware.js`)) {
    middlewares = require(`${rootPath}/src/app/server/middleware.js`)(
        middlewares,
    );
}
github alphagov / paas-admin / src / components / app / app.ts View on Github external
res: /* istanbul ignore next */ (res: ServerResponse) => ({
        status: res.statusCode,
      }),
    },
  }));

  app.set('trust proxy', true);

  app.use(cookieSession({
    name: 'pazmin-session',
    keys: [config.sessionSecret],
    secure: !config.allowInsecureSession,
    httpOnly: true,
  }));

  app.use('/assets', staticGzip('dist/assets', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/govuk-frontend/govuk', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/govuk-frontend/govuk/assets', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/d3/dist', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/d3-sankey/dist', {immutable: true}));
  app.use(compression());

  app.use(helmet());
  app.use(helmet.contentSecurityPolicy(csp));

  app.use(express.urlencoded({extended: true}));
  app.use(csrf());

  app.get('/healthcheck', (_req: express.Request, res: express.Response) => res.send({message: 'OK'}));

  app.get('/forbidden', () => {
    throw new NotAuthorisedError('Forbidden');
github Autodesk-Forge / forge-rcdb.nodejs / src / server / index.js View on Github external
app.use('/resources', express.static(__dirname + '/../../resources'))

  app.get('*', express.static(path.resolve(process.cwd(), './dist')))

} else {

  if (process.env.SERVE_STATIC) {

    app.use('/resources', express.static(__dirname + '/../../resources'))
  }

  app.use(gzip(path.resolve(process.cwd(), './dist'), {
    enableBrotli: true
  }))

  app.get('*', gzip(path.resolve(process.cwd(), './dist'), {
    enableBrotli: true
  }))
}

/////////////////////////////////////////////////////////////////////
//
//
/////////////////////////////////////////////////////////////////////
const runServer = (app) => {

  try {

    process.on('exit', () => {

    })
github alphagov / paas-admin / src / components / app / app.ts View on Github external
status: res.statusCode,
      }),
    },
  }));

  app.set('trust proxy', true);

  app.use(cookieSession({
    name: 'pazmin-session',
    keys: [config.sessionSecret],
    secure: !config.allowInsecureSession,
    httpOnly: true,
  }));

  app.use('/assets', staticGzip('dist/assets', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/govuk-frontend/govuk', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/govuk-frontend/govuk/assets', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/d3/dist', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/d3-sankey/dist', {immutable: true}));
  app.use(compression());

  app.use(helmet());
  app.use(helmet.contentSecurityPolicy(csp));

  app.use(express.urlencoded({extended: true}));
  app.use(csrf());

  app.get('/healthcheck', (_req: express.Request, res: express.Response) => res.send({message: 'OK'}));

  app.get('/forbidden', () => {
    throw new NotAuthorisedError('Forbidden');
  });
github alphagov / paas-admin / src / components / app / app.ts View on Github external
}),
    },
  }));

  app.set('trust proxy', true);

  app.use(cookieSession({
    name: 'pazmin-session',
    keys: [config.sessionSecret],
    secure: !config.allowInsecureSession,
    httpOnly: true,
  }));

  app.use('/assets', staticGzip('dist/assets', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/govuk-frontend', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/govuk-frontend/assets', {immutable: true}));
  app.use('/assets', staticGzip('src/frontend/javascript', { immutable: true }));
  app.use(compression());

  app.use(helmet());
  app.use(helmet.contentSecurityPolicy(csp));

  app.use(express.urlencoded({extended: true}));

  app.get('/healthcheck', (_req: express.Request, res: express.Response) => res.send({message: 'OK'}));

  app.get('/calculator', (req: express.Request, res: express.Response, next: express.NextFunction) => {
    const route = router.findByName('admin.home');
    const ctx = initContext(req, router, route, config);

    getCalculator(ctx, {...req.query, ...req.params, ...route.parser.match(req.path)})
      .then((response: IResponse) => {
github alphagov / paas-admin / src / components / app / app.ts View on Github external
},
  }));

  app.set('trust proxy', true);

  app.use(cookieSession({
    name: 'pazmin-session',
    keys: [config.sessionSecret],
    secure: !config.allowInsecureSession,
    httpOnly: true,
  }));

  app.use('/assets', staticGzip('dist/assets', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/govuk-frontend/govuk', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/govuk-frontend/govuk/assets', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/d3/dist', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/d3-sankey/dist', {immutable: true}));
  app.use(compression());

  app.use(helmet());
  app.use(helmet.contentSecurityPolicy(csp));

  app.use(express.urlencoded({extended: true}));
  app.use(csrf());

  app.get('/healthcheck', (_req: express.Request, res: express.Response) => res.send({message: 'OK'}));

  app.get('/forbidden', () => {
    throw new NotAuthorisedError('Forbidden');
  });

  app.get('/calculator', (req: express.Request, res: express.Response, next: express.NextFunction) => {
github Autodesk-Forge / forge-rcdb.nodejs / src / server / index.js View on Github external
}))

  app.use(webpackHotMiddleware(compiler))

  app.use('/resources', express.static(__dirname + '/../../resources'))

  app.get('*', express.static(path.resolve(process.cwd(), './dist')))

} else {

  if (process.env.SERVE_STATIC) {

    app.use('/resources', express.static(__dirname + '/../../resources'))
  }

  app.use(gzip(path.resolve(process.cwd(), './dist'), {
    enableBrotli: true
  }))

  app.get('*', gzip(path.resolve(process.cwd(), './dist'), {
    enableBrotli: true
  }))
}

/////////////////////////////////////////////////////////////////////
//
//
/////////////////////////////////////////////////////////////////////
const runServer = (app) => {

  try {
github alphagov / paas-admin / src / components / app / app.ts View on Github external
}));

  app.set('trust proxy', true);

  app.use(cookieSession({
    name: 'pazmin-session',
    keys: [config.sessionSecret],
    secure: !config.allowInsecureSession,
    httpOnly: true,
  }));

  app.use('/assets', staticGzip('dist/assets', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/govuk-frontend/govuk', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/govuk-frontend/govuk/assets', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/d3/dist', {immutable: true}));
  app.use('/assets', staticGzip('node_modules/d3-sankey/dist', {immutable: true}));
  app.use(compression());

  app.use(helmet());
  app.use(helmet.contentSecurityPolicy(csp));

  app.use(express.urlencoded({extended: true}));
  app.use(csrf());

  app.get('/healthcheck', (_req: express.Request, res: express.Response) => res.send({message: 'OK'}));

  app.get('/forbidden', () => {
    throw new NotAuthorisedError('Forbidden');
  });

  app.get('/calculator', (req: express.Request, res: express.Response, next: express.NextFunction) => {
    const route = router.findByName('admin.home');
github bbc / simorgh / src / server / index.jsx View on Github external
const getPublicDirectory = () =>
  process.env.NODE_ENV === 'production'
    ? process.env.RAZZLE_PUBLIC_DIR
    : process.env.RAZZLE_PUBLIC_DIR_DEV;

const publicDirectory = getPublicDirectory();
const dataFolderToRender =
  process.env.NODE_ENV === 'production' ? 'data/prod' : 'data/test';

const server = express();
server
  .disable('x-powered-by')
  .use(compression())
  .use('/data', express.static(dataFolderToRender))
  .use(
    expressStaticGzip(publicDirectory, {
      enableBrotli: true,
      orderPreference: ['br'],
    }),
  )
  .get('/status', (req, res) => {
    res.sendStatus(200);
  })
  .get('/*', async ({ url }, res) => {
    try {
      const sheet = new ServerStyleSheet();
      const data = await loadInitialData(url, routes);

      const app = renderToString(
        sheet.collectStyles(
          ,
        ),

express-static-gzip

simple wrapper on top of express.static, that allows serving pre-gziped files

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis

Popular express-static-gzip functions