mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-27 16:52:40 +08:00
Add support for static files.
This commit is contained in:
@@ -29,13 +29,6 @@
|
|||||||
<NoWarn>1701;1702</NoWarn>
|
<NoWarn>1701;1702</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Remove="wwwroot\**" />
|
|
||||||
<Content Remove="wwwroot\**" />
|
|
||||||
<EmbeddedResource Remove="wwwroot\**" />
|
|
||||||
<None Remove="wwwroot\**" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Update="appsettings.json">
|
<Content Update="appsettings.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
@@ -72,11 +65,13 @@
|
|||||||
<None Update="Web\authorization_handler.py">
|
<None Update="Web\authorization_handler.py">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Update="Web\wwwroot\Hello.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Properties\PublishProfiles\" />
|
<Folder Include="Properties\PublishProfiles\" />
|
||||||
<Folder Include="Web\wwwroot\" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Microsoft.Extensions.Hosting;
|
|||||||
using MQTTnet.Server.Web;
|
using MQTTnet.Server.Web;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace MQTTnet.Server
|
namespace MQTTnet.Server
|
||||||
@@ -21,8 +22,8 @@ namespace MQTTnet.Server
|
|||||||
webBuilder.ConfigureKestrel(serverOptions =>
|
webBuilder.ConfigureKestrel(serverOptions =>
|
||||||
{
|
{
|
||||||
})
|
})
|
||||||
|
.UseWebRoot(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Web", "wwwroot"))
|
||||||
.UseStartup<Startup>();
|
.UseStartup<Startup>();
|
||||||
|
|
||||||
}).Build().Run();
|
}).Build().Run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
World
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>paho JS Example</title>
|
||||||
|
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
var mqttClient = new Paho.MQTT.Client("localhost", 80, "/mqtt", "pahoJS_client");
|
||||||
|
mqttClient.onConnectionLost = onConnectionLost;
|
||||||
|
mqttClient.onMessageArrived = onMessageArrived;
|
||||||
|
mqttClient.connect({ onSuccess: onConnect });
|
||||||
|
|
||||||
|
function onConnect() {
|
||||||
|
console.log("MQTT client connected");
|
||||||
|
mqttClient.subscribe("pahoJS_subscription");
|
||||||
|
}
|
||||||
|
|
||||||
|
function onConnectionLost(responseObject) {
|
||||||
|
if (responseObject.errorCode !== 0) {
|
||||||
|
console.log("onConnectionLost:" + responseObject.errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMessageArrived(message) {
|
||||||
|
console.log("onMessageArrived:" + message.payloadString);
|
||||||
|
}
|
||||||
|
function buttonClick() {
|
||||||
|
message = new Paho.MQTT.Message("Hello");
|
||||||
|
message.destinationName = "pahoJS_topic";
|
||||||
|
mqttClient.send(message);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<button onclick="buttonClick()">Publish</button>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user