mirror of
https://github.com/Damillora/Fuyuko
synced 2024-11-21 12:57:32 +00:00
Initial commit
This commit is contained in:
parent
faa03f519d
commit
e562868f2a
@ -1,3 +1,3 @@
|
||||
# Fuyuko
|
||||
|
||||
A minimal framework for creating Gemini-based applications
|
||||
A Node-based Gemini server running on gemini.nanao.moe
|
||||
|
33
handlers/fileServer.js
Normal file
33
handlers/fileServer.js
Normal file
@ -0,0 +1,33 @@
|
||||
const mime = require('mime-types');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
var handleFile = function(filePath, req, res, next) {
|
||||
fs.lstat(filePath, function(err,stats) {
|
||||
if(err) {
|
||||
if(err.code === 'ENOENT') {
|
||||
next();
|
||||
}
|
||||
}
|
||||
if(stats.isDirectory()) {
|
||||
if(filePath.endsWith("/")) {
|
||||
handleFile(path.join(filePath,'/index.gmi'), req, res, next);
|
||||
} else {
|
||||
res.redirect(req.path+"/");
|
||||
}
|
||||
return;
|
||||
}
|
||||
fs.open(filePath, 'r', function (err, fd) {
|
||||
var contents = fs.readFileSync(fd);
|
||||
res.meta = "text/gemini";
|
||||
res.end(contents);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function(documentRoot) {
|
||||
return function(req, res, next) {
|
||||
var filePath = path.join(process.env.DOCUMENT_ROOT, req.path);
|
||||
handleFile(filePath,req,res,next);
|
||||
}
|
||||
}
|
29
index.js
Normal file
29
index.js
Normal file
@ -0,0 +1,29 @@
|
||||
const {createServer, DEFAULT_PORT} = require('@derhuerst/gemini')
|
||||
const fs = require('fs');
|
||||
|
||||
// handlers
|
||||
var fileServer = require("./handlers/fileServer");
|
||||
|
||||
const handleRequest = (req, res) => {
|
||||
var handlers = [
|
||||
fileServer(process.env.DOCUMENT_ROOT)
|
||||
];
|
||||
var idx = 0;
|
||||
var next = function() {
|
||||
idx++;
|
||||
if(idx == handlers.length) {
|
||||
res.notFound();
|
||||
return;
|
||||
}
|
||||
handlers[idx](req,res,next);
|
||||
}
|
||||
handlers[idx](req,res,next);
|
||||
}
|
||||
|
||||
const server = createServer({
|
||||
cert: fs.readFileSync(process.env.TLS_CERT_PATH),
|
||||
key: fs.readFileSync(process.env.TLS_KEY_PATH),
|
||||
}, handleRequest)
|
||||
|
||||
server.listen(DEFAULT_PORT)
|
||||
server.on('error', console.error)
|
14
package.json
Normal file
14
package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "asahi",
|
||||
"version": "1.0.0",
|
||||
"description": "Gemini server used at gemini.nanao.moe",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/Damillora/Fuyuko",
|
||||
"author": "Damillora",
|
||||
"license": "MIT",
|
||||
"private": false,
|
||||
"dependencies": {
|
||||
"@derhuerst/gemini": "^1.1.1",
|
||||
"mime-types": "^2.1.28"
|
||||
}
|
||||
}
|
91
yarn.lock
Normal file
91
yarn.lock
Normal file
@ -0,0 +1,91 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@derhuerst/gemini@^1.1.1":
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@derhuerst/gemini/-/gemini-1.1.1.tgz#6d5a0e41883dcc760e0cb196e3057df21383bf99"
|
||||
integrity sha512-TKc5c1gMCk8gGCzU32RBxncAUrrthMM4S7M3S5NLmtiTDc5SrM9oC3MQFczuA9yDs796u7cjIU540iL/6lFwFA==
|
||||
dependencies:
|
||||
debug "^4.1.1"
|
||||
pem "^1.14.4"
|
||||
|
||||
charenc@0.0.2:
|
||||
version "0.0.2"
|
||||
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"
|
||||
integrity sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc=
|
||||
|
||||
crypt@0.0.2:
|
||||
version "0.0.2"
|
||||
resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b"
|
||||
integrity sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs=
|
||||
|
||||
debug@^4.1.1:
|
||||
version "4.3.1"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee"
|
||||
integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==
|
||||
dependencies:
|
||||
ms "2.1.2"
|
||||
|
||||
es6-promisify@^6.0.0:
|
||||
version "6.1.1"
|
||||
resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-6.1.1.tgz#46837651b7b06bf6fff893d03f29393668d01621"
|
||||
integrity sha512-HBL8I3mIki5C1Cc9QjKUenHtnG0A5/xA8Q/AllRcfiwl2CZFXGK7ddBiCoRwAix4i2KxcQfjtIVcrVbB3vbmwg==
|
||||
|
||||
is-buffer@~1.1.6:
|
||||
version "1.1.6"
|
||||
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
|
||||
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==
|
||||
|
||||
isexe@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
|
||||
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
|
||||
|
||||
md5@^2.2.1:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/md5/-/md5-2.3.0.tgz#c3da9a6aae3a30b46b7b0c349b87b110dc3bda4f"
|
||||
integrity sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==
|
||||
dependencies:
|
||||
charenc "0.0.2"
|
||||
crypt "0.0.2"
|
||||
is-buffer "~1.1.6"
|
||||
|
||||
mime-db@1.45.0:
|
||||
version "1.45.0"
|
||||
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.45.0.tgz#cceeda21ccd7c3a745eba2decd55d4b73e7879ea"
|
||||
integrity sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==
|
||||
|
||||
mime-types@^2.1.28:
|
||||
version "2.1.28"
|
||||
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.28.tgz#1160c4757eab2c5363888e005273ecf79d2a0ecd"
|
||||
integrity sha512-0TO2yJ5YHYr7M2zzT7gDU1tbwHxEUWBCLt0lscSNpcdAfFyJOVEpRYNS7EXVcTLNj/25QO8gulHC5JtTzSE2UQ==
|
||||
dependencies:
|
||||
mime-db "1.45.0"
|
||||
|
||||
ms@2.1.2:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
|
||||
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
|
||||
|
||||
os-tmpdir@^1.0.1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"
|
||||
integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=
|
||||
|
||||
pem@^1.14.4:
|
||||
version "1.14.4"
|
||||
resolved "https://registry.yarnpkg.com/pem/-/pem-1.14.4.tgz#a68c70c6e751ccc5b3b5bcd7af78b0aec1177ff9"
|
||||
integrity sha512-v8lH3NpirgiEmbOqhx0vwQTxwi0ExsiWBGYh0jYNq7K6mQuO4gI6UEFlr6fLAdv9TPXRt6GqiwE37puQdIDS8g==
|
||||
dependencies:
|
||||
es6-promisify "^6.0.0"
|
||||
md5 "^2.2.1"
|
||||
os-tmpdir "^1.0.1"
|
||||
which "^2.0.2"
|
||||
|
||||
which@^2.0.2:
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"
|
||||
integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==
|
||||
dependencies:
|
||||
isexe "^2.0.0"
|
Loading…
Reference in New Issue
Block a user