• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript connect-livereload类代码示例发布时间:2022-05-28
下一篇:
TypeScript connect类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap