添加启动页(部署有效、子站点有效果),方便确认部署是否成功及功能导航。

main
bicijinlian 15 hours ago
parent c45d4da443
commit b73d00a5c5

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>McpStudy.McpServerSSE</title>
</head>
<body>
<div style="text-align:center">
<h2>McpStudy.McpServerSSE 启动成功!</h2>
<h3>WebAPI参阅<a id="GoSwagger" href="#">Swagger 文档</a></h3>
<h3>MCP服务测试<a id="GoMCP" href="#">MCP服务页</a></h3>
</div>
<script type="text/javascript">
//相对根路径
var baseUrl = document.baseURI;
baseUrl = baseUrl.replace(/\/$/, "");
//设置Swagger地址
var swaggerUrl = baseUrl + "/swagger/index.html";
//设置连接地址
document.getElementById("GoSwagger").setAttribute("href", swaggerUrl);
//设置MCP服务器地址
var mcpServerUrl = baseUrl + "/sse";
//设置连接地址
document.getElementById("GoMCP").setAttribute("href", mcpServerUrl);
</script>
</body>
</html>

@ -16,4 +16,10 @@
<ProjectReference Include="..\McpStudy.Core\McpStudy.Core.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Index.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

@ -23,21 +23,33 @@ public class Program
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.MapOpenApi();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/openapi/v1.json", "v1");
});
}
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/openapi/v1.json", "v1");
});
app.UseAuthorization();
app.MapControllers();
//配置启动地址(支持子站点):自定义中间件+重定向
//只能用中间件,不能用路由(app.Map): / 和 "" 会优先被app.MapMcp处理
app.Use(async (context, next) =>
{
if (context.Request.Path == "/" || context.Request.Path == "")
{
context.Response.ContentType = "text/html";
await context.Response.SendFileAsync(Path.Combine(app.Environment.ContentRootPath, "index.html"));
}
else
{
await next();
}
});
app.MapMcp();
app.Run();

Loading…
Cancel
Save