当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript connect-history-api-fallback类代码示例

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


在下文中一共展示了connect-history-api-fallback类的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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。