How to use forcedomain - 1 common examples

To help you get started, we’ve selected a few forcedomain 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 OpenMined / openmined-website / server / server.js View on Github external
createExpressMiddleware,
  skipRequireExtensions
} from 'create-react-server';

import app from '../src/app';
import template from './template';

try {
  skipRequireExtensions();

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

  if (process.env.HOST_NAME) {
    express.use(
      forceDomain({
        hostname: process.env.HOST_NAME,
        protocol: process.env.FORCE_SSL === 'true' ? 'https' : 'http'
      })
    );
  }

  // NOTE: Currently this just redirects all former blog and dig posts to the new URL
  // It will be a glorious day that we don't need this anymore...
  express.get('*', (req, res, next) => {
    if (req.path.indexOf('/blog') === -1 && req.path.indexOf('/digs') === -1) {
      return next();
    } else {
      let params = req.path.split('/');
      params = params.filter(n => n !== '' && n !== '[object%20Object]');

      if (params.length === 1) {

forcedomain

forcedomain is a middleware for Connect and Express that redirects any requests to a default domain.

MIT
Latest version published 3 years ago

Package Health Score

48 / 100
Full package analysis

Popular forcedomain functions