コード例 #1
0
    public DefaultSpaStaticFileProvider(
        IServiceProvider serviceProvider,
        SpaStaticFilesOptions options)
    {
        if (options == null)
        {
            throw new ArgumentNullException(nameof(options));
        }

        if (string.IsNullOrEmpty(options.RootPath))
        {
            throw new ArgumentException($"The {nameof(options.RootPath)} property " +
                                        $"of {nameof(options)} cannot be null or empty.");
        }

        var env = serviceProvider.GetRequiredService <IWebHostEnvironment>();
        var absoluteRootPath = Path.Combine(
            env.ContentRootPath,
            options.RootPath);

        // PhysicalFileProvider will throw if you pass a non-existent path,
        // but we don't want that scenario to be an error because for SPA
        // scenarios, it's better if non-existing directory just means we
        // don't serve any static files.
        if (Directory.Exists(absoluteRootPath))
        {
            _fileProvider = new PhysicalFileProvider(absoluteRootPath);
        }
    }
コード例 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();
            services.Configure <FlightManagerConfig>(Configuration.GetSection("FlightManagerConfig"));
            services.AddSingleton(Configuration);

            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy", builder => builder
                                  .WithOrigins("http://localhost:4200")
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });

            services.AddControllersWithViews();
            services.AddSignalR();
            services.AddSingleton <SimLinkClient>();
            services.AddSingleton <SimLinkHub>();
            services.AddSingleton <AirportService>();

            //In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
            var spaConfig = new SpaStaticFilesOptions {
                RootPath = "ClientApp/dist"
            };

            services.AddSingleton(spaConfig);
            services.AddTransient <ISpaStaticFileProvider, StevesSpaStaticFileProvider>();
        }
コード例 #3
0
 private void ConfigureSpaStaticFiles(SpaStaticFilesOptions options)
 {
     // In production, the UI files will be served from this directory
     options.RootPath = "BaGet.UI/build";
 }
コード例 #4
0
 public static void ConfigureSpaStaticFiles(SpaStaticFilesOptions options) =>
 options.RootPath = "App/build";