Move to ES6 modules
* Move to ES6 modules * Start working on a GeminiServer class * Create a package.json
This commit is contained in:
parent
86546c42f9
commit
a6f5a2cd62
|
@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
6
main.js
6
main.js
|
@ -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"),
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue