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


TypeScript connect-history-api-fallback.default方法代碼示例

本文整理匯總了TypeScript中connect-history-api-fallback.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript connect-history-api-fallback.default方法的具體用法?TypeScript connect-history-api-fallback.default怎麽用?TypeScript connect-history-api-fallback.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在connect-history-api-fallback的用法示例。


在下文中一共展示了connect-history-api-fallback.default方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: express

import * as historyApiFallback from 'connect-history-api-fallback';

import * as express from "express";

const app = express();
app.use(historyApiFallback());

historyApiFallback({
    verbose: true
});

historyApiFallback({
    logger: console.log.bind(console)
});

historyApiFallback({
    rewrites: [
        { from: /\/soccer/, to: '/soccer.html' }
    ]
});

historyApiFallback({
    index: 'default.html'
});

historyApiFallback({
    htmlAcceptHeaders: ['text/html', 'application/xhtml+xml']
});

historyApiFallback({
    rewrites: [
開發者ID:Crevil,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:connect-history-api-fallback-tests.ts

示例2: init

/**
 * This function initiates the server.
 */
function init(){
    bs.init({
        server : {
            baseDir : './dist',
            routes: {
                "/node_modules": "node_modules"
            }
        },
        middleware: [historyApiFallBack()]
    });
}
開發者ID:NablaT,項目名稱:FarmCity,代碼行數:14,代碼來源:gulp-serve.ts

示例3: serverDev

/**
 * This function initialises the server in development mode.
 */
function serverDev() {
    bs.init({
        server: {
            baseDir: DEV_PATH + '/',
            routes: {
                "/node_modules": "node_modules"
            }
        },
        injectChanges: true,
        middleware: [historyApiFallback()],
    });
}
開發者ID:rudkodm,項目名稱:closer-ui,代碼行數:15,代碼來源:gulp-serve.ts

示例4: serverProd

/**
 * This function initialises the server in production mode.
 */
function serverProd() {
    bs.init({
        server: {
            baseDir: PROD_PATH + '/',
            routes: {
                "/node_modules": "node_modules"
            }
        },
        middleware: [historyApiFallback(), compress()],
        ghostMode: false,
        ui: false,
        notify: false,
        port: process.env.PORT || 3000
    });
}
開發者ID:rudkodm,項目名稱:closer-ui,代碼行數:18,代碼來源:gulp-serve.ts

示例5:

gulp.task('serve', () => {
  browserSync.init({
    notify: false,
    server: {
      baseDir: [DIR_TMP, DIR_SRC],
      middleware: [historyApiFallback()],
      routes: {
        '/bower_components': 'bower_components',
        '/node_modules': 'node_modules'
      }
    }
  });
  gulp.watch(`${DIR_SRC}/**/*.ts`, ['ts-watch']);
  gulp.watch(`${DIR_SRC}/**/*.{css,html}`, null).on('change', browserSync.reload);
});
開發者ID:Farata,項目名稱:polymer-typescript-starter,代碼行數:15,代碼來源:gulpfile-dev.ts

示例6: createServer

export function createServer(options: ServerOptions): JspmHmrServer {

  // APP
  const app = express();

  // Apply gzip compression
  app.use(compress());

  // TODO: CORS
  // const headers = {
  //   'Access-Control-Allow-Origin': '*',
  //   'Access-Control-Allow-Credentials': 'true',
  // };

  // Apply Proxy middleware
  if (options.proxy) {
    const proxyTarget = options.proxy;
    const proxyRoute = options.proxyRoute || '*';

    const proxyServer = httpProxy.createProxyServer();
    app.use(proxyRoute, (req, res) => {
      req.url = `${req.originalUrl}`;
      proxyServer.web(req, res, { target: proxyTarget });
      proxyServer.on('error', (err: Error) => {
        console.log('Proxy Server Error: ', err.message);
      });
    });
  }

  // Apply Fallback middleware to rewrite route requests
  // and serve /index.html for SPA Applications
  if (options.fallback) {
    const fallback = options.fallback === true ? '/index.html' : options.fallback;
    console.log('history api fallback active', fallback);

    app.use(historyApiFallback({
      index: fallback, verbose: !!options.verbose,
    }));
  }

  // Cache config
  const cache = options.cache && options.cache * 1000 || -1;
  // Server static files with cache headers
  const staticRoot = options.path || '.';
  console.log(`static files served from ${path.resolve(staticRoot)}`);
  app.use(express.static(staticRoot, { maxAge: cache }));

  // Creating NodeJS Server Instance
  let serverInstance;
  if (options.ssl) {
    const key = options.key || Config.KEY_PATH;
    const cert = options.cert || Config.CERT_PATH;

    const sslOptions = (key && cert) && {
      key: fs.readFileSync(key),
      cert: fs.readFileSync(cert),
    };

    serverInstance = https.createServer(sslOptions, app);
  } else {
    serverInstance = http.createServer(app);
  }

  // Creating Chokidar Socket.io Server
  if (!options.disableHmr) {
    const chokidarOptions = {
      ...{ quiet: false, path: options.path },
      app: serverInstance,
    };

    chokidar(chokidarOptions);
  }

  return serverInstance;
}
開發者ID:piotrwitek,項目名稱:jspm-hmr,代碼行數:75,代碼來源:jspm-hmr-server.ts


注:本文中的connect-history-api-fallback.default方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。