Skip to content

Commit b48ff89

Browse files
committed
Bind EmbedIO to any ("*") address and make sure that the HTML file is retrieved via EmbedIO and not directly from the assets.
1 parent c356e6e commit b48ff89

3 files changed

Lines changed: 11 additions & 28 deletions

File tree

‎src/EmbedIO.Forms.Sample/EmbedIO.Forms.Sample.sln‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Global
4242
{2DF46817-4AEA-4A47-B72C-919C3D040C9F}.AppStore|iPhoneSimulator.Deploy.0 = Release|Any CPU
4343
{2DF46817-4AEA-4A47-B72C-919C3D040C9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4444
{2DF46817-4AEA-4A47-B72C-919C3D040C9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
45+
{2DF46817-4AEA-4A47-B72C-919C3D040C9F}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
4546
{2DF46817-4AEA-4A47-B72C-919C3D040C9F}.Debug|iPhone.ActiveCfg = Debug|Any CPU
4647
{2DF46817-4AEA-4A47-B72C-919C3D040C9F}.Debug|iPhone.Build.0 = Debug|Any CPU
4748
{2DF46817-4AEA-4A47-B72C-919C3D040C9F}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU

‎src/EmbedIO.Forms.Sample/EmbedIO.Forms.Sample/App.xaml.cs‎

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Unosquare.Labs.EmbedIO.Modules;
66
using Xamarin.Forms;
77
using Xamarin.Forms.Xaml;
8+
using System.Reflection;
89

910
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
1011
namespace EmbedIO.Forms.Sample
@@ -15,38 +16,20 @@ public App()
1516
{
1617
InitializeComponent();
1718

18-
MainPage = new MainPage();
19-
}
20-
21-
protected override void OnStart()
22-
{
23-
// Handle when your app starts
19+
// Server must be started, before WebView is initialized,
20+
// because we have no reload implemented in this sample.
2421
Task.Factory.StartNew(async () =>
2522
{
26-
using (var server = new WebServer("http://" + GetLocalIpAddress() + ":8080"))
23+
using (var server = new WebServer("http://*:8080"))
2724
{
28-
server.RegisterModule(new LocalSessionModule());
29-
server.Module<StaticFilesModule>().UseRamCache = true;
30-
server.Module<StaticFilesModule>().DefaultExtension = ".html";
31-
server.Module<StaticFilesModule>().DefaultDocument = "index.html";
25+
Assembly assembly = typeof(App).Assembly;
26+
server.RegisterModule(new ResourceFilesModule(assembly, "EmbedIO.Forms.Sample.html"));
27+
3228
await server.RunAsync();
3329
}
3430
});
35-
}
36-
37-
private static string GetLocalIpAddress()
38-
{
39-
var listener = new TcpListener(IPAddress.Loopback, 0);
40-
41-
try
42-
{
43-
listener.Start();
44-
return ((IPEndPoint)listener.LocalEndpoint).Address.ToString();
45-
}
46-
finally
47-
{
48-
listener.Stop();
49-
}
31+
32+
MainPage = new MainPage();
5033
}
5134
}
5235
}

‎src/EmbedIO.Forms.Sample/EmbedIO.Forms.Sample/MainPage.xaml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
<RowDefinition Height="*" />
1111
</Grid.RowDefinitions>
1212
<wv:FormsWebView x:Name="WebContent"
13-
ContentType="LocalFile"
1413
Grid.Row="0" Grid.Column="0"
15-
Source="html/index.html" />
14+
Source="http://127.0.0.1:8080/index.html" />
1615
</Grid>
1716
</ContentPage>

0 commit comments

Comments
 (0)