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


TypeScript http-proxy-middleware.default函數代碼示例

本文整理匯總了TypeScript中http-proxy-middleware.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1:

      add    : (app, middleware) => {
        app.use(c2k(proxy(
          config.apiPrefixes,
          {
            target: `http://localhost:${config.serverPort + 1}`,
            secure: false,
          },
        ) as NextHandleFunction))

        app.use(c2k(history({
          index  : `${config.serverIndex}`,
          verbose: false,
        }) as NextHandleFunction))

        middleware.webpack()
        // middleware.content()
      },
開發者ID:whitetrefoil,項目名稱:flickr-simple-reorder,代碼行數:17,代碼來源:dev-server.ts

示例2: getApp

export function getApp(options: ServerOptions): express.Express {
  options = applyDefaultServerOptions(options);

  // Preload the h2-push manifest to avoid the cost on first push
  if (options.pushManifestPath) {
    getPushManifest(options.root, options.pushManifestPath);
  }

  const root = options.root || '.';
  const app = express();

  app.use(compression());

  if (options.additionalRoutes) {
    options.additionalRoutes.forEach((handler, route) => {
      app.get(route, handler);
    });
  }

  const componentUrl = options.componentUrl;

  const polyserve = makeApp({
    componentDir: options.componentDir,
    packageName: options.packageName,
    root: root,
    headers: options.headers,
  });

  const filePathRegex: RegExp = /.*\/.+\..{1,}$/;

  if (options.proxy) {
    if (options.proxy.path.startsWith(componentUrl)) {
      console.error(`proxy path can not start with ${componentUrl}.`);
      return;
    }

    let escapedPath = options.proxy.path;

    for (let char of ['*', '?', '+']) {
      if (escapedPath.indexOf(char) > -1) {
        console.warn(
            `Proxy path includes character "${char}"` +
            `which can cause problems during route matching.`);
      }
    }

    if (escapedPath.startsWith('/')) {
      escapedPath = escapedPath.substring(1);
    }
    if (escapedPath.endsWith('/')) {
      escapedPath = escapedPath.slice(0, -1);
    }
    const pathRewrite = {};
    pathRewrite[`^/${escapedPath}`] = '';
    const apiProxy = httpProxy(`/${escapedPath}`, {
      target: options.proxy.target,
      changeOrigin: true,
      pathRewrite: pathRewrite
    });
    app.use(`/${escapedPath}/`, apiProxy);
  }

  const forceCompile = options.compile === 'always';
  if (options.compile === 'auto' || forceCompile) {
    app.use('*', injectCustomElementsEs5Adapter(forceCompile));
    app.use('*', babelCompile(forceCompile, options.componentUrl));
  }

  app.use(`/${componentUrl}/`, polyserve);

  // `send` expects files to be specified relative to the given root and as a
  // URL rather than a file system path.
  const entrypoint =
      options.entrypoint ? urlFromPath(root, options.entrypoint) : 'index.html';

  app.get('/*', (req, res) => {
    pushResources(options, req, res);
    const filePath = req.path;
    send(req, filePath, {root: root, index: entrypoint})
        .on('error',
            (error: send.SendError) => {
              if ((error).status === 404 && !filePathRegex.test(filePath)) {
                // The static file handling middleware failed to find a file on
                // disk. Serve the entry point HTML file instead of a 404.
                send(req, entrypoint, {root: root}).pipe(res);
              } else {
                res.statusCode = error.status || 500;
                res.end(error.message);
              }
            })
        .pipe(res);
  });
  return app;
}
開發者ID:iblancasa,項目名稱:polyserve,代碼行數:94,代碼來源:start_server.ts

示例3: debug

import debug from 'debug';
import express from 'express';
import serveStatic from 'serve-static';
import httpProxy from 'http-proxy-middleware';
import history from 'connect-history-api-fallback';

import { CONFIG } from '@eng/config';

const logger = debug('eng:prod:server');

const app = express();

const apiProxy = httpProxy({
    target: CONFIG.API_TARGET,
    changeOrigin: true,
    pathRewrite: { [`^${CONFIG.API_PREFIX}`]: '' },
    secure: false,
});

app.set('port', process.env.PORT || 5000);

app.use(history());

app.use(serveStatic('dist'));

app.use(`${CONFIG.API_PREFIX}/**`, apiProxy);

app.listen(app.get('port'), (err: any) => {
    if (err) {
        logger(err);
    }
開發者ID:athrunsun,項目名稱:oh-my-stars,代碼行數:31,代碼來源:serve.ts

示例4: httpProxyMiddleware

 Object.keys(httpProxyConfig).forEach(context => {
   const target = httpProxyConfig[context];
   expressApp.use(context, httpProxyMiddleware(context, { target }));
 });
開發者ID:skidding,項目名稱:cosmos,代碼行數:4,代碼來源:httpProxy.ts

示例5: getApp

export function getApp(options: ServerOptions): express.Express {
  options = applyDefaultServerOptions(options);

  // Preload the h2-push manifest to avoid the cost on first push
  if (options.pushManifestPath) {
    getPushManifest(options.root, options.pushManifestPath);
  }

  const root = options.root || '.';
  const app = express();

  if (options.additionalRoutes) {
    options.additionalRoutes.forEach((handler, route) => {
      app.get(route, handler);
    });
  }

  const componentUrl = options.componentUrl;

  const polyserve = makeApp({
    componentDir: options.componentDir,
    packageName: options.packageName,
    root: root,
    headers: options.headers,
  });
  options.packageName = polyserve.packageName;

  const filePathRegex: RegExp = /.*\/.+\..{1,}$/;

  if (options.proxy) {
    if (options.proxy.path.startsWith(componentUrl)) {
      console.error(`proxy path can not start with ${componentUrl}.`);
      return;
    }

    let escapedPath = options.proxy.path;

    for (let char of ['*', '?', '+']) {
      if (escapedPath.indexOf(char) > -1) {
        console.warn(
            `Proxy path includes character "${char}" which can cause problems during route matching.`);
      }
    }

    if (escapedPath.startsWith('/')) {
      escapedPath = escapedPath.substring(1);
    }
    if (escapedPath.endsWith('/')) {
      escapedPath = escapedPath.slice(0, -1);
    }
    const pathRewrite = {};
    pathRewrite[`^/${escapedPath}`] = '';
    const apiProxy = httpProxy(`/${escapedPath}`, {
      target: options.proxy.target,
      changeOrigin: true,
      pathRewrite: pathRewrite
    });
    app.use(`/${escapedPath}/`, apiProxy);
  }

  if (options.compile === 'auto' || options.compile === 'always') {
    app.use('*', babelCompile(options.compile === 'always'));
  }

  app.use(`/${componentUrl}/`, polyserve);

  app.get('/*', (req, res) => {
    pushResources(options, req, res);
    const filePath = req.path;
    send(req, filePath, {root: root})
        .on('error',
            (error: send.SendError) => {
              if ((error).status === 404 && !filePathRegex.test(filePath)) {
                send(req, '/', {root: root}).pipe(res);
              } else {
                res.statusCode = error.status || 500;
                res.end(error.message);
              }
            })
        .pipe(res);
  });
  return app;
}
開發者ID:tony19-contrib,項目名稱:polyserve,代碼行數:83,代碼來源:start_server.ts


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