Let’s deploy a small HTTP service written in .NET on Runway!
Create a new (web) project for your .NET app:
$ dotnet new web -o my-app
Then go into the my-app directory, initialize a git repository (git init).
The Program.cs file will contain your route. Let’s also log all requests (using a middleware) and configure the web server through a PORT environment variable (with a default of 5000):
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
var logger = app.Logger;
string port = Environment.GetEnvironmentVariable("PORT") ?? "5000";
// middleware
app.Use(async (context, next) =>
{
logger.LogInformation("Request: {Method} {Path}",
context.Request.Method,
context.Request.Path);
await next();
});
app.MapGet("/", () => "Hello World!");
app.Run($"http://0.0.0.0:{port}");
Pay special attention to the app.Run(), by default the project will only be available on localhost.
dotnet as well: dotnet run will start the application on http://localhost:3000.Now that all is configured and setup, let’s git commit and deploy!
Create an application on Runway:
$ runway app create
INFO checking login status
INFO created app "ingenious-builder"
create app ingenious-builder: done
next steps:
* commit your changes
* runway app deploy
* runway open
And deploy:
$ runway app deploy && runway open
Congrats, your dotnet app is now on Runway! ✅