Skip to content

Commit cf3e84b

Browse files
CORS and Fixes
- Fixed issue where the last outputs will not be sent.
1 parent afd38f3 commit cf3e84b

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

Program.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,30 @@
33
using Dev.Ide.Hubs;
44
using Microsoft.Extensions.DependencyInjection;
55
using Dev.Ide.Worker;
6+
using static System.Net.WebRequestMethods;
67

78
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/Buffer");
89

10+
var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
11+
912
var builder = WebApplication.CreateBuilder(args);
1013

1114
// Add services to the container.
1215
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
1316
builder.Services.AddSignalR();
1417
builder.Services.AddHostedService<DbHostedService>();
1518

19+
builder.Services.AddCors(options =>
20+
{
21+
options.AddPolicy(name: MyAllowSpecificOrigins,
22+
policy =>
23+
{
24+
policy.WithOrigins("https://oj.tech4good.tech/",
25+
"https://oj-api.tech4good.tech/").AllowAnyHeader().AllowAnyMethod().WithMethods("GET", "POST")
26+
.AllowCredentials().SetIsOriginAllowed(_ => true);
27+
});
28+
});
29+
1630
if (builder.Environment.IsDevelopment())
1731
{
1832

@@ -41,6 +55,8 @@
4155

4256
app.UseRouting();
4357

58+
app.UseCors(MyAllowSpecificOrigins);
59+
4460
app.UseAuthorization();
4561

4662
app.MapControllerRoute(

Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"Dev.Ide": {
1212
"commandName": "Project",
1313
"launchBrowser": true,
14-
"applicationUrl": "http://localhost:4766",
14+
"applicationUrl": "http://localhost:29373",
1515
"environmentVariables": {
1616
"ASPNETCORE_ENVIRONMENT": "Development"
1717
}

Pseudo/PseudoWorker.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,17 @@ public async Task Run()
117117
}*/
118118

119119
p.WaitForExit(1000 * 120);
120+
121+
await Task.Delay(100);
122+
123+
while(outputs.Count > 0 || errors.Count > 0)
124+
{
125+
await Task.Delay(50);
126+
}
127+
120128
p.Close();
129+
130+
121131
p.Dispose();
122132
// display what the process output
123133

@@ -140,7 +150,7 @@ public void Input(string input)
140150

141151
public void Dispose()
142152
{
143-
throw new NotImplementedException();
153+
144154
}
145155
}
146156
}

Worker/DbHostedService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Task StartAsync(CancellationToken cancellationToken)
3030
"Consume Scoped Service Hosted Service is starting.");
3131

3232
_timer = new Timer(DoWork, null, TimeSpan.Zero,
33-
TimeSpan.FromMilliseconds(100));
33+
TimeSpan.FromMilliseconds(50));
3434

3535
return Task.CompletedTask;
3636
}
@@ -91,7 +91,7 @@ private async void DoWork(object state)
9191
}
9292
}
9393

94-
var rootPath = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
94+
var rootPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
9595
foreach (var t in toTerminate)
9696
{
9797
await hub.Clients.Client(t).SendAsync("Complete");

0 commit comments

Comments
 (0)