Move to ES6 modules

* Move to ES6 modules
* Start working on a GeminiServer class
* Create a package.json
This commit is contained in:
MatthiasSaihttam 2021-08-28 16:09:02 -04:00
parent 86546c42f9
commit a6f5a2cd62
3 changed files with 54 additions and 2 deletions

39
GeminiServer.js Normal file
View File

@ -0,0 +1,39 @@
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.");
}
}
}
}

View File

@ -1,5 +1,7 @@
const tls = require("tls");
const fs = require("fs");
import tls from "tls";
import fs from "fs";
import GeminiServer from "./GeminiServer"
const options = {
//cert: fs.readFileSync("public-cert.pem"),

11
package.json Normal file
View File

@ -0,0 +1,11 @@
{
"name": "flying-theater",
"version": "v0.1.0",
"author": "Matthias",
"license": "UNLICENSED",
"type": "module",
"entry": "main.js",
"scripts": {
"start": "node main.js"
}
}