|
@@ -5,14 +5,17 @@ using System.Threading.Tasks;
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
using Microsoft.AspNetCore.HttpsPolicy;
|
|
|
+using Microsoft.AspNetCore.SpaServices;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
+using VueCliMiddleware;
|
|
|
|
|
|
namespace HTEXMarkWeb
|
|
|
{
|
|
|
public class Startup
|
|
|
{
|
|
|
+ readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
|
|
|
public Startup(IConfiguration configuration)
|
|
|
{
|
|
|
Configuration = configuration;
|
|
@@ -22,7 +25,20 @@ namespace HTEXMarkWeb
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
- {
|
|
|
+ { //設定跨域請求
|
|
|
+ services.AddCors(options =>
|
|
|
+ {
|
|
|
+ options.AddPolicy(MyAllowSpecificOrigins,
|
|
|
+ builder =>
|
|
|
+ {
|
|
|
+ builder.WithOrigins("http://teammodelos-test.chinacloudsites.cn",
|
|
|
+ "https://www.teammodel.cn", "https://localhost:5001",
|
|
|
+ "http://localhost:5000", "http://localhost:64524",
|
|
|
+ "https://localhost:44341", "https://localhost:8888", "http://localhost:8888")
|
|
|
+ .AllowAnyHeader()
|
|
|
+ .AllowAnyMethod();
|
|
|
+ });
|
|
|
+ });
|
|
|
services.AddControllersWithViews();
|
|
|
}
|
|
|
|
|
@@ -39,18 +55,37 @@ namespace HTEXMarkWeb
|
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
|
app.UseHsts();
|
|
|
}
|
|
|
- app.UseHttpsRedirection();
|
|
|
- app.UseStaticFiles();
|
|
|
+ //TODO 目前不使用中間件全局攔截Exception,請在API中,明確處理200成功返回值或錯誤碼,Exception一率返回BadRequert 400,並選擇需要返回釘釘群組回報的API
|
|
|
+ //app.UseMiddleware<HttpGlobalExceptionInvoke>();
|
|
|
|
|
|
+ //以下需要按照順序載入中間件 如果应用调用 UseStaticFiles,请将 UseStaticFiles 置于 UseRouting之前。
|
|
|
+ app.UseStaticFiles();
|
|
|
+ //app.UseSpaStaticFiles(); //使用中間件不開
|
|
|
+ // app.UseSpaStaticFiles();
|
|
|
app.UseRouting();
|
|
|
|
|
|
- app.UseAuthorization();
|
|
|
+ app.UseCors(MyAllowSpecificOrigins); //使用跨域設定
|
|
|
+ //app.UseHttpsRedirection(); //開發中暫時關掉
|
|
|
|
|
|
+ //如果应用使用身份验证/授权功能(如 AuthorizePage 或 [Authorize]),请将对 UseAuthentication 和 UseAuthorization的
|
|
|
+ //调用放在之后、UseRouting 和 UseCors,但在 UseEndpoints之前
|
|
|
+ app.UseAuthentication();
|
|
|
+ app.UseAuthorization();
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
{
|
|
|
- endpoints.MapControllerRoute(
|
|
|
- name: "default",
|
|
|
- pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
|
+ endpoints.MapControllers();
|
|
|
+#if DEBUG
|
|
|
+ endpoints.MapToVueCliProxy(
|
|
|
+ "{*path}",
|
|
|
+ new SpaOptions { SourcePath = "ClientApp" },
|
|
|
+ npmScript: (System.Diagnostics.Debugger.IsAttached) ? "serve" : null,
|
|
|
+ // regex: "Compiled successfully",
|
|
|
+ forceKill: true
|
|
|
+ );
|
|
|
+#else
|
|
|
+ endpoints.MapFallbackToFile("index.html");
|
|
|
+#endif
|
|
|
+
|
|
|
});
|
|
|
}
|
|
|
}
|