mollyb is a standalone gemini protocol server and library written in java, without dependencies.
-
serves .gmi files
-
automatically looks for index.gmi in a directory
-
uses TLS (1.2 or 1.3)
-
allows to set a default "not found" page
-
serves media files of type image/jpeg, image/png and image/gif
-
serves feed/xml files
-
writes a basic access log (if so configured)
-
returns a custom "File not found" page (if set) if file or path does not exist
-
dynamic pages/input handling: embedded use only (no cgi support)
- client certificates (Identities)
Assuming you have some recent JDK and maven installed:
-
clone the repository
-
inside the folder, run
mvn package
The server does not directly work with pem files. To help you convert your fullchain.pem and privkey.pem into a .jks (java keystore) file, see the certifcates.sh in the scripts/ folder.
-
Copy the config/config.ini-dist file to config/config.ini
-
Set the required parameters, such as the path to your webroot
java -jar target/mollyb-server.jar /path/to/your/config.ini
Sort of, yes.
gemini://molly.augmentedlogic.com
You can get mollyb from maven central
com.augmentedlogic mollyb 0.7.4import com.augmentedlogic.mollyb.*;
public class Main {
public static void main( String[] args ) {
MollybService ms = new MollybService("0.0.0.0", 1965);
// if you want debug output
ms.setDebug(true);
ms.setWebroot("/path/to/your/webroot");
ms.setKeystore("/path/to/your/keystore.jks");
ms.setKeystorePassword("mysecret");
ms.setKeyPassword("mysecret");
// set a custom not found page
ms.setCustomNotFound("/path/to/your/not_found.gmi");
// logging
ms.setAccessLog("/path/to/your/access.log");
// add a path that will be handle dynamically
ms.addHandler("/dynamic", new ExampleHandler());
try {
ms.start();
} catch(Exception e) {
System.out.println(e);
}
}
}
Note that addHandler() accepts both exact as well as wildcards, e.g. :
ms.addHandler("/dynamic", new ExampleHandler());
or
ms.addHandler("/projects/*", new ExampleHandler());
Now you need a handler, as an example, a handler that will take an input:
import com.augmentedlogic.mollyb.*;
public class ExampleHandler implements GeminiHandler
{
public Response handle(Request request, Response response)
{
if(request.getQuery() == null) {
response.log.debug("client is " + request.getRemoteAddress());
response.setHeader(Response.INPUT_REQUIRED);
} else {
response.setHeader(Response.OK);
response.log.debug("data recieved: " + request.getQuery());
response.addBody("# Hello World");
response.addBody("This is a dynamic page");
response.addBody("QUERY was:" + request.getQuery());
response.addBody("FROM:" + request.getRemoteAddress());
}
return response;
}
}