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
108 changes: 104 additions & 4 deletions src/frontend/src/components/SimpleAppHostCode.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import type { MarkerDefinition } from '@astrojs/starlight/expressive-code';

export type MarkerValueType = MarkerDefinition | MarkerDefinition[] | undefined;
export type CollapseValueType = string | string[] | undefined;
export type LangType = 'csharp' | 'python' | 'nodejs' | 'go' | 'java';

interface CodeProps {
lang?: LangType;
mark?: MarkerValueType;
collapse?: CollapseValueType;
}

const { mark, collapse } = Astro.props as CodeProps;
const { lang = 'csharp', mark, collapse } = Astro.props as CodeProps;

const cs = `
const csharp = `
var builder = DistributedApplication.CreateBuilder(args);

// Add database resource
Expand All @@ -32,12 +34,110 @@ builder.AddViteApp("frontend", "../frontend")

builder.Build().Run();
`;

const python = `
var builder = DistributedApplication.CreateBuilder(args);

// Add database resource
var postgres = builder.AddPostgres("db")
.AddDatabase("appdata")
.WithDataVolume();

// Add API service and reference the database
var api = builder.AddUvicornApp("api", "../api", "main:app")
.WithUv()
.WithReference(postgres)
.WaitFor(postgres);

// Add frontend service and reference the API
builder.AddViteApp("frontend", "../frontend")
.WithHttpEndpoint(env: "PORT")
.WithReference(api);

builder.Build().Run();
`;

const javascript = `
var builder = DistributedApplication.CreateBuilder(args);

// Add database resource
var postgres = builder.AddPostgres("db")
.AddDatabase("appdata")
.WithDataVolume();

// Add API service and reference the database
var api = builder.AddNodeApp("api", "../api", "server.js")
.WithNpm()
.WithReference(postgres)
.WaitFor(postgres);

// Add frontend service and reference the API
builder.AddViteApp("frontend", "../frontend")
.WithHttpEndpoint(env: "PORT")
.WithReference(api);

builder.Build().Run();
`;

const golang = `
var builder = DistributedApplication.CreateBuilder(args);

// Add database resource
var postgres = builder.AddPostgres("db")
.AddDatabase("appdata")
.WithDataVolume();

// Add API service and reference the database
var api = builder.AddGolangApp("api", "../api")
.WithHttpEndpoint(env: "PORT")
.WithReference(postgres)
.WaitFor(postgres);

// Add frontend service and reference the API
builder.AddViteApp("frontend", "../frontend")
.WithHttpEndpoint(env: "PORT")
.WithReference(api);

builder.Build().Run();
`;

const java = `
var builder = DistributedApplication.CreateBuilder(args);

// Add database resource
var postgres = builder.AddPostgres("db")
.AddDatabase("appdata")
.WithDataVolume();

// Add API service and reference the database
var api = builder.AddSpringApp("api", "../api", "otel.jar")
.WithHttpEndpoint(port: 8080)
.WithReference(postgres)
.WaitFor(postgres);

// Add frontend service and reference the API
builder.AddViteApp("frontend", "../frontend")
.WithHttpEndpoint(env: "PORT")
.WithReference(api);

builder.Build().Run();
`;

const codeMap: Record<LangType, string> = {
csharp,
python,
nodejs: javascript,
go: golang,
java,
};

const code = codeMap[lang];
---

<Code
code={cs}
code={code}
lang="cs"
title="C# — AppHost.cs"
title="AppHost.cs"
mark={mark}
collapse={collapse}
collapseStyle={'collapsible-auto'}
Expand Down
Loading
Loading