initial commit

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-05-10 13:23:30 +00:00
commit cd8a9a1168
6 changed files with 135 additions and 0 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
eval "$(lorri direnv)"

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/luarocks
/lua
/lua_modules
/.luarocks

55
gemini.moon Normal file
View File

@ -0,0 +1,55 @@
cqueues = require "cqueues"
socket = require "cqueues.socket"
ln = require "ln"
url = require "net.url"
srv = socket.listen "127.0.0.1", "58816"
cq = cqueues.new!
class ProxyRequestRefusedHandler
run: (ctx, conn) =>
conn\write "53 Proxy request refused \r\n"
ln.log ctx, {status: 53}
class Server
new: (cq, hdlr) =>
@cq = cq
@hdlr = hdlr
listen: (srv) =>
@cq\wrap ->
for conn in srv\clients!
@cq\wrap ->
with conn
_, ip = \peername!
request = \read "*l"
u = url.parse request
ctx =
:ip
host: u.host
path: u.path
query: u.query
@hdlr\run ctx, conn
\close!
-- cq\wrap ->
-- for conn in srv\clients!
-- cq\wrap ->
-- with conn
-- _, ip = \peername!
-- request = \read "*l"
-- u = url.parse request
-- ctx =
-- :ip
-- host: u.host
-- path: u.path
-- query: u.query
-- ln.log ctx
-- \write "53 Proxy request refused\r\n"
-- \close!
with Server cq, ProxyRequestRefusedHandler!
\listen srv
assert cq\loop!

60
nix/lua.nix Normal file
View File

@ -0,0 +1,60 @@
{ pkgs ? import <nixpkgs> { }, fetchurl ? pkgs.fetchurl }:
with pkgs.lua5_3.pkgs;
let
router = buildLuarocksPackage {
pname = "router";
version = "2.1-0";
src = fetchurl {
url = "https://luarocks.org/router-2.1-0.src.rock";
sha256 = "15v2ks5wwv6y7122a1p0r9mh6kfymvh756pb4ax13cy0d0vf362m";
};
disabled = (luaOlder "5.1");
propagatedBuildInputs = [ lua ];
meta = with lib; {
homepage = "https://github.com/APItools/router.lua";
description =
"A barebones router for Lua. It matches urls and executes lua functions";
license.fullName = "MIT";
};
};
net-url = buildLuarocksPackage {
pname = "net-url";
version = "0.9-1";
src = fetchurl {
url = "https://luarocks.org/net-url-0.9-1.src.rock";
sha256 = "12qrb8x95qicq6fp5jfiq6v9h8flngk92bb5vnzph3avpllij3zx";
};
disabled = (luaOlder "5.1");
propagatedBuildInputs = [ lua ];
meta = with lib; {
homepage = "https://github.com/golgote/neturl";
description = "URL and Query string parser, builder, normalizer for Lua.";
license.fullName = "MIT/X11";
};
};
ln = buildLuarocksPackage {
pname = "ln";
version = "0.2.1-2";
src = fetchurl {
url = "https://luarocks.org/ln-0.2.1-2.src.rock";
sha256 = "1hb1vw68w407y05nprp352c0di6iybz4gjdhc0p521cpif4l8i1l";
};
propagatedBuildInputs = [ lua dkjson ];
meta = with lib; {
homepage = "https://tulpa.dev/cadey/lua-ln";
description = "The natural log function";
license.fullName = "0bsd";
};
};
in lua.withPackages (ps: with ps; [ cqueues luaossl router net-url ln ])

13
shell.nix Normal file
View File

@ -0,0 +1,13 @@
{ pkgs ? import <nixpkgs> { } }:
let lua = pkgs.callPackage ./nix/lua.nix { };
in pkgs.mkShell {
buildInputs = with pkgs;
with lua53Packages; [
luarocks-nix
lua
busted
moonscript
];
}

2
var/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore