almost working
This commit is contained in:
parent
828b93c43c
commit
4c1d9baa41
14 changed files with 1690 additions and 0 deletions
67
bin/cozybot.dart
Normal file
67
bin/cozybot.dart
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import "dart:convert";
|
||||
import "dart:io";
|
||||
import "package:cozybot/controllers/record_controller.dart";
|
||||
import "package:riverpod/riverpod.dart";
|
||||
import "package:shelf/shelf.dart";
|
||||
import "package:shelf/shelf_io.dart";
|
||||
import "package:shelf_router/shelf_router.dart";
|
||||
|
||||
void main(List<String> argsRaw) async {
|
||||
final container = ProviderContainer();
|
||||
|
||||
final handler = const Pipeline()
|
||||
.addMiddleware(logRequests())
|
||||
.addHandler(
|
||||
(Router()
|
||||
..get(
|
||||
"/",
|
||||
(_) => Response.ok(
|
||||
"""
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<script>
|
||||
setInterval(async () => {
|
||||
const response = await fetch("/data")
|
||||
const data = await response.json()
|
||||
document.body.innerText = data
|
||||
console.log(data)
|
||||
}, 1000)
|
||||
</script>
|
||||
<style>
|
||||
body {
|
||||
background-color: black;
|
||||
font-size: 25vw;
|
||||
color: white;
|
||||
font-family: "Inter";
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
</html>""",
|
||||
headers: {"content-type": "text/html"},
|
||||
),
|
||||
)
|
||||
..get(
|
||||
"/data",
|
||||
(_) => Response.ok(
|
||||
json.encode(container.read(RecordController.provider)),
|
||||
headers: {"content-type": "text/json"},
|
||||
),
|
||||
))
|
||||
.call,
|
||||
);
|
||||
|
||||
final server = HttpServer.listenOn(
|
||||
await ServerSocket.bind(
|
||||
InternetAddress(
|
||||
"/var/run/cozybot/socket",
|
||||
type: InternetAddressType.unix,
|
||||
),
|
||||
0,
|
||||
),
|
||||
);
|
||||
|
||||
serveRequests(server, handler);
|
||||
print("Bot listening at ${server.address.address}:${server.port}");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue