Initial commit

This commit is contained in:
Tristan B. Velloza Kildaire 2023-02-19 18:29:51 +02:00
commit 0244c41f77
3 changed files with 76 additions and 0 deletions

16
.gitignore vendored Normal file
View File

@ -0,0 +1,16 @@
.dub
docs.json
__dummy.html
docs/
/nostdir
nostdir.so
nostdir.dylib
nostdir.dll
nostdir.a
nostdir.lib
nostdir-test-*
*.exe
*.pdb
*.o
*.obj
*.lst

12
dub.json Normal file
View File

@ -0,0 +1,12 @@
{
"authors": [
"Tristan B. Velloza Kildaire"
],
"copyright": "Copyright © 2023, Tristan B. Velloza Kildaire",
"dependencies": {
"vibe-d": "~>0.9.5"
},
"description": "Nostr directory service",
"license": "AGPL v3.0",
"name": "nostdir"
}

48
source/nostdir/app.d Normal file
View File

@ -0,0 +1,48 @@
module nostdir.app;
import std.stdio;
import vibe.vibe;
import std.json : JSONValue;
void lookupHandler(HTTPServerRequest req, HTTPServerResponse resp)
{
auto queryParameters = req.query();
// TODO: Insert a check for the key we are looking for
string username = queryParameters["name"];
// TODO: JSON to return
JSONValue json;
JSONValue namesBlock;
// TODO: Lookup key here
string key;
namesBlock[username] = key;
json["names"] = namesBlock;
resp.writeBody(json.toPrettyString());
}
void main()
{
writeln("Edit source/app.d to start your project.");
// Setup where to listen
HTTPServerSettings httpSettings = new HTTPServerSettings();
// TODO: Customize these with a config file or environment variables
httpSettings.port = 8081;
// Set a GET handler for `/.well-known/nostr.json?<username>`
URLRouter router = new URLRouter();
router.get("/.well-known/nostr.json", &lookupHandler);
// Bind the router to the server
listenHTTP(httpSettings, router);
runApplication();
}