astronomical-theater/GeminiServer.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

export default class GeminiServer {
constructor(options) {
this.certificates = {};
if (options.hasOwnProperty("host")) {
this.usingSNI = true;
for (const certificate of options.host) {
for (const hostname of options.host.hostnames) {
this.certificates[hostname] = {
hostname,
key: certificate.key,
cert: certificate.cert
}
}
}
}else {
this.usingSNI = false;
this.certificates[options.hostname] = {
hostname: options.hostname,
key: options.key,
cert: options.cert
}
}
//A list of registered paths and their handlers. The first one that matches is used
this.pathRegistry = [];
}
registerPath(path, handler) {
if (!path.startsWith("/")) {
//Then we're dealing with a hostname
if (!this.usingSNI) {
throw new Error("Passed non-absolute path to registerPath.");
}
}
}
}