Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
dotnet-version: |
8.0.x
9.0.x
10.0.x
- name: Installl WASM workloads
run: dotnet workload install wasm-tools --skip-manifest-update
- name: Install dependencies
run: dotnet restore
- name: Locate MSBuild with vswhere
Expand All @@ -36,13 +39,24 @@ jobs:
& $env:MSBUILD AspNetCore.sln /p:Configuration=Debug /p:Platform="Any CPU"
- name: Test Zapto.AspNetCore.NetFx
run: dotnet test --no-restore --no-build --verbosity normal tests/Zapto.AspNetCore.NetFx.Tests/Zapto.AspNetCore.NetFx.Tests.csproj
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install wrangler
run: npm install -g wrangler
- name: Test Zapto.AspNetCore.Wasm
run: dotnet test --verbosity normal tests/Zapto.AspNetCore.Wasm.Tests/Zapto.AspNetCore.Wasm.Tests.csproj
- name: Publish
uses: GerardSmit/publish-nuget@v4.0.2
if: github.ref == 'refs/heads/main'
with:
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
VERSION_FILE_PATH: src/Directory.Build.props
PROJECT_FILE_PATH: |
src/Zapto.AspNetCore.Wasm.Interop/Zapto.AspNetCore.Wasm.Interop.csproj
src/Zapto.AspNetCore.Wasm/Zapto.AspNetCore.Wasm.csproj
src/Zapto.AspNetCore.Polyfill/Zapto.AspNetCore.Polyfill.csproj
src/Zapto.AspNetCore.NetFx/Zapto.AspNetCore.NetFx.csproj
sdk/Zapto.AspNetCore.CloudFlare.SDK/Zapto.AspNetCore.CloudFlare.SDK.csproj

288 changes: 242 additions & 46 deletions AspNetCore.sln

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>

<PropertyGroup>
<Version>1.0.0-alpha.2</Version>
<PackageVersion>1.0.0-alpha.2</PackageVersion>
<Authors>Zapto</Authors>
<RepositoryUrl>https://github.com/zapto-dev/AspNetCore</RepositoryUrl>
<Copyright>Copyright © 2025 Zapto</Copyright>
<PackageTags>zapto, aspnetcore</PackageTags>
<PackageProjectUrl>https://github.com/zapto-dev/AspNetCore</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

</Project>
9 changes: 9 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
<add key="dotnet-experimental" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json" />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
8 changes: 8 additions & 0 deletions sandbox/WasmApp.Library/Example.wasmlib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Greets a person by name.
* @param {string} name - The name of the person to greet.
* @returns {Promise<string>} A greeting message.
*/
export function greet(name) {
return Promise.resolve(`Greetings from Example, ${name}!`);
}
13 changes: 13 additions & 0 deletions sandbox/WasmApp.Library/NativeMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Zapto.AspNetCore.Wasm.Interop;

namespace WasmApp.Library;

public static partial class NativeMethods
{
/// <summary>
/// Calls the JavaScript greet function from the Example module.
/// WASM import: Example_greet(byte* namePtr, int nameLen, int callbackId)
/// </summary>
[WasmLibraryImport("greet", "Example")]
public static partial Task<string?> GreetAsync(string name);
}
23 changes: 23 additions & 0 deletions sandbox/WasmApp.Library/WasmApp.Library.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Zapto.AspNetCore.Wasm.Interop\Zapto.AspNetCore.Wasm.Interop.csproj" />
<ProjectReference Include="..\..\src\Zapto.AspNetCore.Wasm.SourceGenerator\Zapto.AspNetCore.Wasm.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<Content Include="Example.wasmlib.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>

</Project>
44 changes: 44 additions & 0 deletions sandbox/WasmApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using WasmApp.Library;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRouting();

builder.Services.ConfigureHttpJsonOptions(options =>
{
options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonContext.Default);
});

var app = builder.Build();

app.UseRouting();

app.MapGet("/", () => "Hello from ASP.NET Core on Cloudflare Workers!");

app.MapGet("/api/time", () =>
{
return Results.Json(new TimeResponse(DateTime.UtcNow.ToString("O")), AppJsonContext.Default.TimeResponse);
});

app.MapGet("/api/greet/{name}", (string name) => $"Hello, {name}!");

app.MapGet("/library/greet/{name}", async (string name) => await NativeMethods.GreetAsync(name));

app.MapPost("/api/echo", async context =>
{
using var reader = new StreamReader(context.Request.Body);
var body = await reader.ReadToEndAsync(context.RequestAborted);
await context.Response.WriteAsync($"Echo: {body}");
});

await app.RunAsync();

internal record TimeResponse([property: JsonPropertyName("time")] string Time);

[JsonSerializable(typeof(TimeResponse))]
internal partial class AppJsonContext : JsonSerializerContext;
18 changes: 18 additions & 0 deletions sandbox/WasmApp/WasmApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- Import SDK props -->
<Import Project="..\..\sdk\Zapto.AspNetCore.CloudFlare.SDK\Sdk\Sdk.props" />

<PropertyGroup>
<TargetFrameworks>net10.0-browser;net10.0</TargetFrameworks>

<!-- For local development, reference the project directly -->
<ZaptoWasmUseProjectReference>true</ZaptoWasmUseProjectReference>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\WasmApp.Library\WasmApp.Library.csproj" />
</ItemGroup>

<!-- Import SDK targets -->
<Import Project="..\..\sdk\Zapto.AspNetCore.CloudFlare.SDK\Sdk\Sdk.targets" />
</Project>
Loading
Loading