Skip to content
Merged
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
8 changes: 6 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"portsAttributes": {
"5000": {
"label": "ASP.NET API",
"visibility": "public"
"onAutoForward": "openPreview"
},
"27017": {
"label": "MongoDB Atlas Local"
Expand All @@ -28,5 +28,9 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"postCreateCommand": "dotnet restore && bash /workspaces/mongodb-dotnet-example/.devcontainer/track.sh created || true",
"postStartCommand": "echo 'Startup seed runs when the API starts (StartupBehaviorSettings:SeedOnStartup=true by default).'; bash /workspaces/mongodb-dotnet-example/.devcontainer/track.sh started || true"
"postStartCommand": "echo 'Startup seed runs when the API starts (StartupBehaviorSettings:SeedOnStartup=true by default).'; bash /workspaces/mongodb-dotnet-example/.devcontainer/track.sh started || true",
"postAttachCommand": {
"api": "dotnet run --urls http://localhost:5000",
"portSetup": "sleep 5 && .devcontainer/portSetup.sh"
}
}
22 changes: 22 additions & 0 deletions .devcontainer/portSetup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -e

if [ -z "$CODESPACE_NAME" ]; then
echo "Not running in a codespace, exiting."
exit
fi

echo "Installing GH"

(type -p wget >/dev/null || (sudo apt update && sudo apt install wget -y)) \
&& sudo mkdir -p -m 755 /etc/apt/keyrings \
&& out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \
&& cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
&& sudo mkdir -p -m 755 /etc/apt/sources.list.d \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y

echo "Exposing ports"
gh codespace ports visibility 5000:public 27017:public -c $CODESPACE_NAME
2 changes: 2 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -48,6 +49,7 @@
gamesService.SeedIfEmpty(GameSeedData.DefaultGames);
}

app.MapGet("/", () => Results.Redirect("/swagger"));
app.MapControllers();
app.MapHealthChecks("/health");

Expand Down
Loading