diff --git a/.gitignore b/.gitignore index 8a58cfa..91eeade 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,4 @@ package-lock.json certificate.crt private.key main.js -dist -config.json -www -custom.css \ No newline at end of file +dist \ No newline at end of file diff --git a/README.MD b/README.MD deleted file mode 100644 index 63c4e9f..0000000 --- a/README.MD +++ /dev/null @@ -1,11 +0,0 @@ -# Zephyrus -Zephyrus is a *VERY* simple HTTP(S) webserver written in TypeScript. Take a look on our [wiki](https://git.disroot.org/adrianvictor/zephyrus/wiki) for setup instructions. - -## Main features -- HTTPS support. -- Directory listing with custom CSS (with a trick you should also be able to use custom JS). -- Default page when accessing root. -- Automatic MIME type detection. - -## Disclaimer -This project was made just to test my skills, there is no need to use it instead of a well-known more robust server software. diff --git a/package.json b/package.json index da90783..efee649 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,10 @@ "name": "zephyrus-webserver", "description": "A simple webserver that supports directory listing.", "author": "Adrian Victor de Abreu Alves ", - "version": "1.0.1", + "version": "1.0.0", "private": false, "scripts": { - "start": "ts-node zephyrus.ts", + "start": "ts-node main.ts", "build" : "npx tsc" }, "devDependencies": { diff --git a/zephyrus.ts b/zephyrus.ts index 5077054..0553555 100644 --- a/zephyrus.ts +++ b/zephyrus.ts @@ -22,10 +22,9 @@ if(config.useHTTPS) { function requestHandler(request: IncomingMessage, response: ServerResponse) { const parsed = url.parse(request.url || '/', true); const path_ = decodeURI(parsed.pathname || '/'); - const serversidePath = path.resolve(config.serverRoot + path_); - const defaultPagePath = path.resolve(config.serverRoot + config.defaultPage); - const finalPath = (config.useDefaultPage && request.url == '/') ? path.normalize(defaultPagePath) : serversidePath; - // console.log(finalPath) + const serversidePath = path.join(config.serverRoot + path_); + const defaultPagePath = path.join(config.serverRoot + config.defaultPage); + const finalPath = config.useDefaultPage && request.url == '/' ? path.normalize(defaultPagePath) : serversidePath; function showError(code: number, log: boolean = config.logErrors, info: string = 'no more information about the error was provided.') { if (log) { @@ -71,7 +70,7 @@ function requestHandler(request: IncomingMessage, response: ServerResponse) { } // console.log(`Requested ${path_}, accessing ${config.useDefaultPage && request.url == '/' ? defaultPagePath : serversidePath}`) - if (!finalPath.startsWith(path.resolve(config.serverRoot))) { + if (!finalPath.startsWith(path.normalize(config.serverRoot))) { showError(403, undefined, `someone is trying to access files (${finalPath}) outside server root (${config.serverRoot})`) return; } @@ -126,6 +125,6 @@ function requestHandler(request: IncomingMessage, response: ServerResponse) { }) } -server.listen(config.port, () => { - console.log(`Started at http${config.useHTTPS ? 's' : ''}://localhost:${config.port}`) +server.listen(3000, () => { + console.log("Started at https://localhost:3000") }) \ No newline at end of file