nostril/source/app.d

56 lines
1.2 KiB
D
Raw Normal View History

2023-02-21 16:14:51 +02:00
import std.stdio;
import vibe.vibe;
import std.json;
2023-02-21 18:08:50 +02:00
import gogga;
2023-02-21 16:14:51 +02:00
// TODO: Investigate if we need the belowe (I copied it from Birchwood)
2023-02-21 18:08:50 +02:00
__gshared GoggaLogger logger;
2023-02-21 16:14:51 +02:00
__gshared static this()
{
2023-02-21 18:08:50 +02:00
logger = new GoggaLogger();
2023-02-21 16:14:51 +02:00
}
2023-02-21 18:08:50 +02:00
2023-02-21 16:14:51 +02:00
/**
* Handles an incoming websocket connection
* Params:
* socket = the web socket to the client
*/
void websocketHandler(scope WebSocket socket)
{
logger.print("Handling web socket: "~to!(string)(socket)~"\n",DebugType.INFO);
2023-02-21 16:14:51 +02:00
string receivedText = socket.receiveText();
logger.print(receivedText~"\n", DebugType.INFO);
2023-02-21 16:14:51 +02:00
JSONValue jsonReceived;
jsonReceived = parseJSON(receivedText);
logger.print(jsonReceived.toPrettyString()~"\n", DebugType.INFO);
2023-02-21 16:14:51 +02:00
}
void main()
{
// Setup where to listen
HTTPServerSettings httpSettings = new HTTPServerSettings();
// TODO: Customize these with a config file or environment variables
httpSettings.port = 8082;
// Setup a websocket negotiater with a handler attached
auto websocketNegotiater = handleWebSockets(&websocketHandler);
// Handle `/` as the web socket path
URLRouter router = new URLRouter();
router.get("/", websocketNegotiater);
// Bind the router to the server
listenHTTP(httpSettings, router);
runApplication();
}