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

TypeScript connect类代码示例

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

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



在下文中一共展示了connect类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: protractor

function protractor(callback, args, testId: string) {
  const buildConfig = require('../../build/config');
  const app = connect().use(serveStatic(PROJECT_ROOT));
  const protractorHttpServer = createServer(app).listen(buildConfig.protractorPort);

  console.log(`Serving ${process.cwd()} on http://localhost:${buildConfig.protractorPort}`);

  const child = spawn('protractor', args, {
    stdio: [process.stdin, process.stdout, 'pipe']
  });

  let errored = false;
  let callbackCalled = false;

  child.stderr.on('data', function(data) {
    protractorHttpServer.close();
    console.error(data.toString());
    if (!errored) {
      errored = true;
      if (!callbackCalled) {
        callback('Protractor tests failed.');
        callbackCalled = true;
      }
    }
  });

  child.on('exit', function() {
    protractorHttpServer.close();
    if (!callbackCalled) {
      console.log(`[snapshot] TestId: ${testId}`);
      callback();
      callbackCalled = true;
    }
  });
}
开发者ID:JackMj,项目名称:ionic,代码行数:35,代码来源:snapshot.ts


示例2: devCommand

export async function devCommand(config: Config, args) {
  const port = args["x"] || args["port"] || 8000;
  const path = args["p"] || args["path"] || process.cwd();
  const workingDir = await searchForProjectDir(path);
  const servePath = join(workingDir, config.caches.DEPLOY_DIR);
  const lede = loadLede(workingDir, config.logger);
  const logger = config.logger;

  // Dependency instantiation
  const deployer = new lede.deployers.FileSystemDeployer({workingDir: servePath, logger});
  const htmlCompiler = new lede.compilers.NunjucksCompiler(Object.assign({}, config.htmlCompilerArgs, {logger}));
  const styleCompiler = new lede.compilers.SassCompiler(Object.assign({}, config.styleCompilerArgs, { cacheDir: config.caches.COMPILER_CACHE, logger }));
  const scriptCompiler = new lede.compilers.Es6Compiler(Object.assign({}, config.scriptCompilerArgs, { cacheDir: config.caches.COMPILER_CACHE, logger }));
  const projectDirector = new lede.ProjectDirector({ workingDir, depCacheDir: config.caches.DEP_CACHE, deployer, logger, htmlCompiler, scriptCompiler, styleCompiler, debug: true });
  const fileServer = connect();
  const lrServer = livereload.createServer();

  await projectDirector.compile();

  await initializeWatchers({ workingDir, depCacheDir: config.caches.DEP_CACHE, projectDirector});
  fileServer.use(serveStatic(servePath));
  fileServer.listen(port);
  const pageModels = await Promise.all(
    projectDirector.model.pages.map(p => projectDirector.model.getPageTree({name: p.name, debug: true}))
  );
  const livereloadPaths = pageModels.map(p => join(servePath, p.context.$PROJECT.$name, p.context.$PAGE.$name));
  lrServer.watch(livereloadPaths);
  logger.info(`Project ${projectDirector.model.project.name} has finished compiling and is being watched for changes.`);
  for (let page of pageModels) {
    logger.info(`Serving ${page.context.$PAGE.$name} at http://localhost:${port}/${page.context.$PROJECT.$name}/${page.context.$PAGE.$name}`);
  }
  return new Promise((resolve, reject) => {

  });
}
开发者ID:tbtimes,项目名称:lede-cli,代码行数:35,代码来源:dev.ts


示例3: createConnectApp

function createConnectApp(options: CreateAppOptions = {}) {
  const app = connect();

  options.apolloOptions = options.apolloOptions || { schema: Schema };
  if (!options.excludeParser) {
    app.use('/graphql', bodyParser.json());
  }
  if (options.graphiqlOptions ) {
    app.use('/graphiql', graphiqlConnect( options.graphiqlOptions ));
  }
  app.use('/graphql', apolloConnect( options.apolloOptions ));
  return app;
}
开发者ID:HriBB,项目名称:apollo-server,代码行数:13,代码来源:connectApollo.test.ts


示例4: constructor

    constructor(config: Config) {
        super();
        // var middleware = this.intercept.bind(this);
        this.config = config;
        const { port, protocol, target, targetPort, path } = config;
        const url = `${protocol}://${target}:${targetPort || "80"}${path || ""}`;

        this.app = connect();
        // PROXY SET
        config.target = url;
        this.proxy = httpProxy.createProxyServer(config);
        this.proxy.on('error', (err)=> {
            return console.log(err);
        });
    }
开发者ID:thehachez,项目名称:maduk,代码行数:15,代码来源:proxy.ts


示例5: createConnectApp

function createConnectApp(options: CreateAppOptions = {}) {
  const app = connect();
  // We do require users of ApolloServer with connect to use a query middleware
  // first. The alternative is to add a 'isConnect' bool to ServerRegistration
  // and make qs-middleware be a dependency of this package. However, we don't
  // think many folks use connect outside of Meteor anyway, and anyone using
  // connect is probably already using connect-query or qs-middleware.
  app.use(query());
  const server = new ApolloServer(
    (options.graphqlOptions as Config) || { schema: Schema },
  );
  // See comment on ServerRegistration.app for its typing.
  server.applyMiddleware({ app: app as any });
  return app;
}
开发者ID:simonjoom,项目名称:react-native-project,代码行数:15,代码来源:connectApollo.test.ts


示例6: devCommand

export async function devCommand({workingDir, args, logger}) {
  let name = args['n'] || args['name'];
  let port = args['x'] || args['port'] || 8000;
  let {servePath, buildPath} = await getPaths(workingDir, name, logger);
  let compilerPath = args['c'] || args['compilers'] || resolve(workingDir, "compilers", "compilerConfig.js");
  let compilers = await getCompilers(compilerPath, logger);
  let lede = new Lede(buildPath, compilers,
    {dev: new FileSystemDeployer(servePath)}, logger);
  let fileServer = connect();
  let lrServer: any = livereload.createServer();

  fileServer.use(serveStatic(servePath));
  let projectReport = await lede.deploy("dev", true);
  createWatcher({lede, projectReport, logger});
  logger.info(`Serving at ${chalk.green(`localhost:${port}/`)}`);
  lrServer.watch(servePath);
  fileServer.listen(port);
}
开发者ID:tbtimes,项目名称:ledeTwo,代码行数:18,代码来源:devCommand.ts


示例7: constructor

	constructor(host, port) {
		Util.statusMsg('Setting up web server.');

		let protocol = (port === 443) ? 'https' : 'http';
		this.protocol = protocol;
		this.host = host;
		this.port = port;
		this.url = protocol + '://' + host + (protocol === 'http' && port !== 80 ? ':' + port : '') + '/';

		this.index = path.resolve(__dirname, './public');
		this.site = connect();
		this.site.use(serveStatic(this.index));
		this._server = null;

		this.isRestarting = false;
		this.restartPending = false;

		Util.statusMsg('Web server started successfully.');
	}
开发者ID:Itachi2000,项目名称:PS-Bot,代码行数:19,代码来源:web-server.ts


示例8: launchEchoServer

export function launchEchoServer(echoServerPort: number) {

    const echoServer = connect();
    echoServer.use(checkForKillCommand);
    echoServer.use(function(req: IncomingMessage, res: ServerResponse) {
        let urlParts = req.url.split("?");

        let returnResponse = () => {
            res.setHeader('Content-Type', 'text/plain');
            res.writeHead(200);
            req.pipe(res);
        };

        if (urlParts.length > 1) {
            const parameters = querystring.parse(urlParts[1]);

            if (parameters.d) {
                res.setHeader('d', parameters.d);
            }
        
            if (parameters.t) {
                res.setHeader('t', parameters.t);
                setTimeout(returnResponse, parameters.t)
            }
            else {
                returnResponse();
            }
            return;
        }

        returnResponse();

    });

    http.createServer(echoServer).listen(echoServerPort);
    console.log("Echo server listening on " + echoServerPort);
};
开发者ID:roberthardy,项目名称:rp,代码行数:37,代码来源:echoServer.ts


示例9: constructor

    constructor(option: Option) {
      this.option = option;
      this.app = connect();

    }
开发者ID:RecoTwExplorer,项目名称:recotw-proxy,代码行数:5,代码来源:server.ts


示例10: createWebpackDevServer

export function createWebpackDevServer(callback: CreateDevServerCallback, optionsJson: string) {
    const options: CreateDevServerOptions = JSON.parse(optionsJson);
    const webpackConfig: webpack.Configuration = requireNewCopy(options.webpackConfigPath);
    const publicPath = (webpackConfig.output.publicPath || '').trim();
    if (!publicPath) {
        callback('To use the Webpack dev server, you must specify a value for \'publicPath\' on the \'output\' section of your webpack.config.', null);
        return;
    }

    const enableHotModuleReplacement = options.suppliedOptions.HotModuleReplacement;
    const enableReactHotModuleReplacement = options.suppliedOptions.ReactHotModuleReplacement;
    if (enableReactHotModuleReplacement && !enableHotModuleReplacement) {
        callback('To use ReactHotModuleReplacement, you must also enable the HotModuleReplacement option.', null);
        return;
    }

    const app = connect();
    const defaultPort = 0; // 0 means 'choose randomly'. Could allow an explicit value to be supplied instead.
    const listener = app.listen(defaultPort, () => {
        // Build the final Webpack config based on supplied options
        if (enableHotModuleReplacement) {
            // TODO: Stop assuming there's an entry point called 'main'
            if (typeof webpackConfig.entry['main'] === 'string') {
              webpackConfig.entry['main'] = ['webpack-hot-middleware/client', webpackConfig.entry['main']];
            } else {
              webpackConfig.entry['main'].unshift('webpack-hot-middleware/client');
            }
            webpackConfig.plugins.push(
                new webpack.HotModuleReplacementPlugin()
            );

            // Set up React HMR support if requested. This requires the 'aspnet-webpack-react' package.
            if (enableReactHotModuleReplacement) {
                let aspNetWebpackReactModule: any;
                try {
                    aspNetWebpackReactModule = require('aspnet-webpack-react');
                } catch(ex) {
                    callback('To use ReactHotModuleReplacement, you must install the NPM package \'aspnet-webpack-react\'.', null);
                    return;
                }

                aspNetWebpackReactModule.addReactHotModuleReplacementBabelTransform(webpackConfig);
            }
        }

        // Attach Webpack dev middleware and optional 'hot' middleware
        const compiler = webpack(webpackConfig);
        app.use(require('webpack-dev-middleware')(compiler, {
            noInfo: true,
            publicPath: publicPath
        }));

        if (enableHotModuleReplacement) {
            let webpackHotMiddlewareModule;
            try {
                webpackHotMiddlewareModule = require('webpack-hot-middleware');
            } catch (ex) {
                callback('To use HotModuleReplacement, you must install the NPM package \'webpack-hot-middleware\'.', null);
                return;
            }
            app.use(webpackHotMiddlewareModule(compiler));
        }

        // Tell the ASP.NET app what addresses we're listening on, so that it can proxy requests here
        callback(null, {
            Port: listener.address().port,
            PublicPath: removeTrailingSlash(publicPath)
        });
    });
}
开发者ID:MahendraSv,项目名称:NodeServices,代码行数:70,代码来源:WebpackDevMiddleware.ts



注:本文中的connect类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript connect-history-api-fallback类代码示例发布时间:2022-05-28
下一篇:
TypeScript concaveman类代码示例发布时间: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