Made the webroot directory configurable
This commit is contained in:
parent
fa9ca9613d
commit
1d3aa73137
13
config.toml
13
config.toml
@ -1,5 +1,12 @@
|
||||
# Sellery configuration file
|
||||
|
||||
# Serve files from this directory (Path must be absolute)
|
||||
# Use $WORKING_DIR to subsitute the current working directory
|
||||
# So, if you want to server relative paths, use:
|
||||
# $WORKING_DIR/relative/path
|
||||
# Paths should NOT end with a '/'!
|
||||
WEBROOT = '$WORKING_DIR'
|
||||
|
||||
# This is the SHA512 digest to check the password against
|
||||
PASSWD_HASH = 'a3c1443b087cf5338d3696f6029fdf791ee4829a27e19c9f257a06ca0d88b5b518ac9868bb13199e807553bda62d3dc15b6354862f34fcab0a7c4c45530349ea'
|
||||
|
||||
@ -9,7 +16,7 @@ SESSION_DURATION = 600
|
||||
# The port the webserver runs on
|
||||
WEBSERVER_PORT = 443
|
||||
|
||||
# SSL key and certificate (you have to generate these yourself)
|
||||
SSL_KEY_FILE = "key.pem"
|
||||
SSL_CERT_FILE = "cert.pem"
|
||||
# SSL key and certificate (you have to generate these yourself!)
|
||||
SSL_KEY_FILE = 'key.pem'
|
||||
SSL_CERT_FILE = 'cert.pem'
|
||||
|
||||
|
@ -8,6 +8,10 @@ var toml = require('toml');
|
||||
// Parse config file
|
||||
const config = toml.parse(fs.readFileSync('config.toml', 'utf-8'));
|
||||
|
||||
// Compose webroot directory
|
||||
const webrootDir = config.WEBROOT
|
||||
.replace('$WORKING_DIR', __dirname);
|
||||
|
||||
// Just a few mime types
|
||||
const contentTypes = {
|
||||
'.html': 'text/html',
|
||||
@ -181,7 +185,7 @@ function testAuthentication(request, response) {
|
||||
//! This function just serves files as they are...
|
||||
function serverStaticFiles(request, response) {
|
||||
// Fetch requested file
|
||||
fs.readFile(__dirname + request.url, function (error, data) {
|
||||
fs.readFile(webrootDir + request.url, function (error, data) {
|
||||
if(!error) {
|
||||
const mimetype = path.extname(request.url);
|
||||
if (!(typeof mimetype === 'undefined')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user