shithub: rc-gemd

Download patch

ref: ed5406089b36f97cbe0178a8bcb24652f4d4022a
author: Moody <[email protected]>
date: Sun Aug 16 20:13:02 EDT 2020

Initial commit

diff: cannot open b/handlers//null: file does not exist: 'b/handlers//null'
--- /dev/null
+++ b/handlers/error
@@ -1,0 +1,2 @@
+#!/bin/rc
+echo $1^' '^$2^$cr
--- /dev/null
+++ b/handlers/serve-static
@@ -1,0 +1,31 @@
+#!/bin/rc
+full_path=`{echo $"fs_root^$"location | urlencode -d}
+full_path=$"full_path
+
+if(! test -e $full_path){
+	error 41 'file does not exist'
+	exit
+}
+
+if(! test -r $full_path){
+	error 42 'file is not readble'
+	exit
+}
+
+switch($full_path){
+case *.gem *.gemini
+        type=text/gemini
+case *.txt *.md
+        type=text/plain
+case *.jpg *.jpeg
+        type=image/jpeg
+case *.gif
+        type=image/gif
+case *.png
+        type=image/png
+case *
+        type=`{file -m $full_path}
+}
+
+echo 20' '$type^$cr
+cat $full_path
--- /dev/null
+++ b/rc-gemd
@@ -1,0 +1,17 @@
+#!/bin/rc
+rc_gemd_dir=/rc/bin/rc-gemd
+path=(/bin $rc_gemd_dir/handlers)
+cr=
+
+url=`{sed 's/'$cr'//;1q'}
+if(~ $url *://*){
+	scheme=`{echo $url | sed 's,://.*,,g'}
+	url=`{echo $url | sed 's,'^$scheme^'://,,'}
+}
+if not
+	scheme='gemini://'
+
+server_name=`{echo $url | sed 's,/.*,,'}
+location=`{echo $url | sed 's,[a-zA-Z0-9.]+/,/,'}
+
+. $rc_gemd_dir/select-handler
--- /dev/null
+++ b/select-handler
@@ -1,0 +1,3 @@
+#!/bin/rc
+fs_root=/lib/gem
+exec serve-static