Skip to content

Commit c2f3a66

Browse files
davidortinauCopilot
andcommitted
fix: route mobile CoreSync through API instead of web service
Mobile CoreSync was silently failing because iOS/Android only have dev tunnel routes to the 'api' service, not the 'web' service where CoreSync HTTP server was hosted. Added CoreSync server capability to the API project (same DB, same table config) and changed the mobile sync URL from https+http://web to https+http://api. Verified: initial sync pulls all 2472 vocab words + 1670 progress records to the mobile SQLite database. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 433d64d commit c2f3a66

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/SentenceStudio.Api/Program.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
using System.Reflection;
33
using System.Text;
44
using System.Text.Json;
5+
using CoreSync;
6+
using CoreSync.Http.Server;
7+
using CoreSync.Sqlite;
58
using ElevenLabs;
69
using ElevenLabs.Models;
710
using ElevenLabs.TextToSpeech;
@@ -131,6 +134,27 @@
131134
var databasePath = Path.Combine(serverDbFolder, "sentencestudio.db");
132135
builder.Services.AddDataServices(databasePath);
133136

137+
// CoreSync server — allows mobile clients to sync through the API endpoint
138+
// (mobile devices can't reach the separate 'web' service directly)
139+
builder.Services.AddCoreSyncHttpServer();
140+
builder.Services.AddSingleton<ISyncProvider>(sp =>
141+
{
142+
var connectionString = $"Data Source={databasePath}";
143+
var configurationBuilder = new SqliteSyncConfigurationBuilder(connectionString)
144+
.Table<LearningResource>("LearningResource", syncDirection: SyncDirection.UploadAndDownload)
145+
.Table<VocabularyWord>("VocabularyWord", syncDirection: SyncDirection.UploadAndDownload)
146+
.Table<ResourceVocabularyMapping>("ResourceVocabularyMapping", syncDirection: SyncDirection.UploadAndDownload)
147+
.Table<Challenge>("Challenge", syncDirection: SyncDirection.UploadAndDownload)
148+
.Table<Conversation>("Conversation", syncDirection: SyncDirection.UploadAndDownload)
149+
.Table<ConversationChunk>("ConversationChunk", syncDirection: SyncDirection.UploadAndDownload)
150+
.Table<UserProfile>("UserProfile", syncDirection: SyncDirection.UploadAndDownload)
151+
.Table<SkillProfile>("SkillProfile", syncDirection: SyncDirection.UploadAndDownload)
152+
.Table<VocabularyList>("VocabularyList", syncDirection: SyncDirection.UploadAndDownload)
153+
.Table<VocabularyProgress>("VocabularyProgress", syncDirection: SyncDirection.UploadAndDownload)
154+
.Table<VocabularyLearningContext>("VocabularyLearningContext", syncDirection: SyncDirection.UploadAndDownload);
155+
return new SqliteSyncProvider(configurationBuilder.Build(), ProviderMode.Remote);
156+
});
157+
134158
// Vocabulary progress services
135159
builder.Services.AddSingleton<VocabularyProgressRepository>();
136160
builder.Services.AddSingleton<VocabularyLearningContextRepository>();
@@ -153,6 +177,10 @@
153177

154178
var app = builder.Build();
155179

180+
// Apply CoreSync provisioning (creates change-tracking tables if missing)
181+
var syncProvider = app.Services.GetRequiredService<ISyncProvider>();
182+
await syncProvider.ApplyProvisionAsync();
183+
156184
// Configure the HTTP request pipeline.
157185
if (app.Environment.IsDevelopment())
158186
{
@@ -174,6 +202,7 @@
174202
app.UseCors(app.Environment.IsDevelopment() ? "AllowDevClients" : "AllowWebApp");
175203
app.UseAuthentication();
176204
app.UseAuthorization();
205+
app.UseCoreSyncHttpServer();
177206
app.UseMiddleware<TenantContextMiddleware>();
178207

179208
// Auth endpoints (anonymous — they handle login/register)

src/SentenceStudio.Api/SentenceStudio.Api.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11+
<PackageReference Include="CoreSync.Http.Server" Version="0.1.122" />
12+
<PackageReference Include="CoreSync.Sqlite" Version="0.1.122" />
1113
<PackageReference Include="ElevenLabs-DotNet" Version="3.7.1" />
1214
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.1" />
1315
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="10.2.0-preview.1.26063.2" />

src/SentenceStudio.AppLib/Setup/SentenceStudioAppBuilder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public static MauiAppBuilder UseSentenceStudioApp(this MauiAppBuilder builder)
5353
// MauiServiceDefaults → AddServiceDiscovery(). When launched from Aspire,
5454
// env vars (services__api__https__0 etc.) override the config. When launched
5555
// manually, the Services section in appsettings.json provides fallback URLs.
56-
var syncServerUri = new Uri("https+http://web");
56+
// CoreSync server is hosted on the API (not the separate 'web' service) so
57+
// mobile clients can reach it through the existing dev tunnel / service discovery.
58+
var syncServerUri = new Uri("https+http://api");
5759
builder.Services.AddSyncServices(dbPath, syncServerUri);
5860

5961
var apiBaseUri = new Uri("https+http://api");

0 commit comments

Comments
 (0)