-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
49 lines (40 loc) · 1.27 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using xjtf.d.ui._2;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseWindowsService(opt => opt.ServiceName = "Xjtf Daemon");
builder.Services.AddControllers();
builder.Services.AddWindowsService();
builder.Services.AddHostedService<ServiceMonitor>();
builder.Services.AddDbContext<XjtfDbContext>(options => {
options.UseSqlite("Data Source=xjtf.db");
});
var app = builder.Build();
EnsureCreated.DatabaseReady(app);
// Fallback to `index.html` for React Router
app.Use(async (context, next) =>
{
if (context.Request.Path.Value!.StartsWith("/api"))
{
await next();
return;
}
if (context.Request.Path.Value == "/")
{
context.Request.Path = "/index.html";
await next();
return;
}
await next();
});
// Serve static files from the embedded resource store
app.UseMiddleware<EmbeddedResourceMiddleware>();
// Serve static files from the React build folder
// var reactAppPath = Path.Combine(Directory.GetCurrentDirectory(), "ClientApp", "dist");
// app.UseStaticFiles(new StaticFileOptions
// {
// FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(reactAppPath),
// RequestPath = ""
// });
// Map API endpoints
app.MapControllers();
app.Run();