Create example usage to design to
This commit is contained in:
parent
1314e3c6ff
commit
86546c42f9
|
@ -0,0 +1,47 @@
|
|||
const GeminiServer = require("./main.js").GeminiServer;
|
||||
const staticFileHandler = require("./main.js").staticFileHandler;
|
||||
|
||||
const server = new GeminiServer({
|
||||
// port: 1965
|
||||
//Option 1 (a single hostname):
|
||||
// hostname:
|
||||
// key:
|
||||
// cert
|
||||
//Option 2 (if you want virtual hosting)
|
||||
host: [
|
||||
{
|
||||
hostnames: ["localhost"],
|
||||
key: "key",
|
||||
cert: "",
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
//Registering a path with a string returns the string as Gemini text
|
||||
server.registerPath("localhost/", "### Hello, world");
|
||||
//Anything before the first slash is a domain name and is used in SNI matching if you passed the `host` option
|
||||
server.registerPath("MacBookGamma.local/", "### Hello from my Mac!");
|
||||
|
||||
//Otherwise, you have a function, a handler
|
||||
//request has everything you would expect, .servername, .path,
|
||||
//You have to provide the entire responce inc. content type
|
||||
server.registerPath("localhost/allFiles", request => "text/txt\r\nHello, World\r\n");
|
||||
|
||||
// We provide some convenient handlers for static, CGI, and reverse proxy
|
||||
|
||||
//if the passed file is a single file, it's a file. If it's a directory, all sub-files are auto-included
|
||||
server.registerPath("localhost/static", staticFileHandler("/file/root" /*, {options}*/));
|
||||
|
||||
//The file passed to CGI handler must exist and be executable at run time
|
||||
//You know what, CGIHandler hashes the file
|
||||
//No dynamically generated or changed CGI files
|
||||
//No enabling CGI running for a certain file extension
|
||||
//No enabling CGI running for a certain path. This must take a single file
|
||||
//500 CGI files, you better write 500 registerPath's (or write a custom handler)
|
||||
server.registerPath("localhost/run", CGIhandler("/path/to/test.py"));
|
||||
|
||||
//Kinda cursed but whatever
|
||||
server.registerPath("localhost/thoughts", proxyHandler("gemini://localhost:8888"));
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue