public AttachmentService(PublicContext publicContext, IAttachmentPathProvider attachmentPathProvider, IPreviewGeneratorService previewGeneratorService, IHttpContextAccessor httpContext)
 {
     _publicContext           = publicContext;
     _attachmentPathProvider  = attachmentPathProvider;
     _previewGeneratorService = previewGeneratorService;
     _httpContext             = httpContext;
 }
示例#2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IAttachmentPathProvider attachmentPathProvider)
        {
            loggerFactory.AddFile(Path.Combine(Directory.GetCurrentDirectory(), "log.log"));

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseStaticFiles();
            app.ConfigureCustomExceptionMiddleware();

            //app.UseHttpsRedirection();

            var basePath = "/api/attachment";

            app.UseCors(x => x.AllowAnyOrigin());
            app.UseCors(x => x.AllowAnyHeader());

            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(attachmentPathProvider.GetPath(), "Files")),
                RequestPath  = new PathString("/Files")
            });


            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            if (env.IsDevelopment())
            {
                app.UseSwagger();
            }
            else
            {
                app.UseSwagger(c => c.PreSerializeFilters.Add((swaggerDoc, httpReq) =>
                {
                    swaggerDoc.Servers = new List <OpenApiServer>
                    {
                        new OpenApiServer {
                            Url = $"{httpReq.Scheme}://{httpReq.Host.Value}{basePath}"
                        }
                    };
                }));
            }

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("./v1/swagger.json", "My API V1");
                c.InjectJavascript("https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js");
                c.InjectJavascript("https://unpkg.com/browse/[email protected]/dist/browser-polyfill.min.js", type: "text/html");
                c.InjectJavascript("https://gistcdn.githack.com/Forevka/dede3d7ac835e24518ec38a349140dac/raw/94d095aebdc460d42f90732be5c4ec057ac0a374/customJs.js");
            });
        }