コード例 #1
0
        public static void Attach(
            ISpaBuilder spaBuilder,
            string npmScriptName,
            string compiledSuccessfullyString)
        {
            var sourcePath = spaBuilder.Options.SourcePath;

            if (string.IsNullOrEmpty(sourcePath))
            {
                throw new ArgumentNullException(nameof(sourcePath));
            }
            if (string.IsNullOrEmpty(npmScriptName))
            {
                throw new ArgumentNullException(nameof(npmScriptName));
            }
            CompiledSuccessfullyString = compiledSuccessfullyString;
            var logger        = LoggerFinder.GetOrCreateLogger(spaBuilder.ApplicationBuilder, LogCategoryName);
            var targetUriTask = StartCreateVueAppServerAsync(sourcePath, npmScriptName, logger)
                                .ContinueWith(task => new UriBuilder("http", "127.0.0.1", task.Result).Uri);

            spaBuilder.UseProxyToSpaDevelopmentServer(() =>
            {
                var startupTimeout = spaBuilder.Options.StartupTimeout;
                return(targetUriTask.WithTimeout(startupTimeout,
                                                 $"在 {startupTimeout.Seconds} 秒钟的超时时间内,Vue服务器未开始侦听请求。 检查日志输出以获取错误信息"));
            });
        }
コード例 #2
0
            TimeSpan.FromSeconds(5);     // This is a development-time only feature, so a very long timeout is fine

        public static void Attach(
            ISpaBuilder spaBuilder,
            string npmScriptName)
        {
            var sourcePath = spaBuilder.Options.SourcePath;

            if (string.IsNullOrEmpty(sourcePath))
            {
                throw new ArgumentException("Cannot be null or empty", nameof(sourcePath));
            }

            if (string.IsNullOrEmpty(npmScriptName))
            {
                throw new ArgumentException("Cannot be null or empty", nameof(npmScriptName));
            }

            // Start create-react-app and attach to middleware pipeline
            var appBuilder = spaBuilder.ApplicationBuilder;
            var logger     = LoggerFinder.GetOrCreateLogger(appBuilder, LogCategoryName);
            var portTask   = StartCreateVueAppServerAsync(sourcePath, npmScriptName, logger);

            // Everything we proxy is hardcoded to target http://localhost because:
            // - the requests are always from the local machine (we're not accepting remote
            //   requests that go directly to the create-react-app server)
            // - given that, there's no reason to use https, and we couldn't even if we
            //   wanted to, because in general the create-react-app server has no certificate
            var targetUriTask = portTask.ContinueWith(
                task => new UriBuilder("http", "localhost", task.Result).Uri);

            spaBuilder.UseProxyToSpaDevelopmentServer(() =>
            {
                // On each request, we create a separate startup task with its own timeout. That way, even if
                // the first request times out, subsequent requests could still work.
                var timeout = spaBuilder.Options.StartupTimeout;
                return(targetUriTask.WithTimeout(timeout,
                                                 $"The Vue development server did not start listening for requests " +
                                                 $"within the timeout period of {timeout.Seconds} seconds. " +
                                                 $"Check the log output for error information."));
            });
        }