Compare commits

...

9 commits

Author SHA1 Message Date
Tenkuma
2a9e8ad7ba
Update README.MD 2025-12-10 01:52:57 -03:00
202e591f35 Update README.MD 2024-11-17 02:07:41 +01:00
71521ca67f Update README.MD 2024-11-17 02:03:02 +01:00
75e2e9faa9 Update README.MD 2024-11-17 02:02:24 +01:00
4baefd6662 Added screenshot to readme.md 2024-11-17 02:00:55 +01:00
e9805e4526 Added readme.md 2024-11-17 01:57:47 +01:00
Adrian Victor
ac7c2104b4 Changed version code. 2024-11-16 21:25:19 -03:00
Adrian Victor
0dad0cce04 Sanitized paths 2024-11-16 21:22:51 -03:00
Adrian Victor
7455199177 Added port option in config.json 2024-11-16 15:32:56 -03:00
4 changed files with 24 additions and 9 deletions

3
.gitignore vendored
View file

@ -4,3 +4,6 @@ certificate.crt
private.key private.key
main.js main.js
dist dist
config.json
www
custom.css

11
README.MD Normal file
View file

@ -0,0 +1,11 @@
# 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.

View file

@ -2,10 +2,10 @@
"name": "zephyrus-webserver", "name": "zephyrus-webserver",
"description": "A simple webserver that supports directory listing.", "description": "A simple webserver that supports directory listing.",
"author": "Adrian Victor de Abreu Alves <adrianvictor@disroot.org>", "author": "Adrian Victor de Abreu Alves <adrianvictor@disroot.org>",
"version": "1.0.0", "version": "1.0.1",
"private": false, "private": false,
"scripts": { "scripts": {
"start": "ts-node main.ts", "start": "ts-node zephyrus.ts",
"build" : "npx tsc" "build" : "npx tsc"
}, },
"devDependencies": { "devDependencies": {

View file

@ -22,9 +22,10 @@ if(config.useHTTPS) {
function requestHandler(request: IncomingMessage, response: ServerResponse) { function requestHandler(request: IncomingMessage, response: ServerResponse) {
const parsed = url.parse(request.url || '/', true); const parsed = url.parse(request.url || '/', true);
const path_ = decodeURI(parsed.pathname || '/'); const path_ = decodeURI(parsed.pathname || '/');
const serversidePath = path.join(config.serverRoot + path_); const serversidePath = path.resolve(config.serverRoot + path_);
const defaultPagePath = path.join(config.serverRoot + config.defaultPage); const defaultPagePath = path.resolve(config.serverRoot + config.defaultPage);
const finalPath = config.useDefaultPage && request.url == '/' ? path.normalize(defaultPagePath) : serversidePath; const finalPath = (config.useDefaultPage && request.url == '/') ? path.normalize(defaultPagePath) : serversidePath;
// console.log(finalPath)
function showError(code: number, log: boolean = config.logErrors, info: string = 'no more information about the error was provided.') { function showError(code: number, log: boolean = config.logErrors, info: string = 'no more information about the error was provided.') {
if (log) { if (log) {
@ -70,7 +71,7 @@ function requestHandler(request: IncomingMessage, response: ServerResponse) {
} }
// console.log(`Requested ${path_}, accessing ${config.useDefaultPage && request.url == '/' ? defaultPagePath : serversidePath}`) // console.log(`Requested ${path_}, accessing ${config.useDefaultPage && request.url == '/' ? defaultPagePath : serversidePath}`)
if (!finalPath.startsWith(path.normalize(config.serverRoot))) { if (!finalPath.startsWith(path.resolve(config.serverRoot))) {
showError(403, undefined, `someone is trying to access files (${finalPath}) outside server root (${config.serverRoot})`) showError(403, undefined, `someone is trying to access files (${finalPath}) outside server root (${config.serverRoot})`)
return; return;
} }
@ -125,6 +126,6 @@ function requestHandler(request: IncomingMessage, response: ServerResponse) {
}) })
} }
server.listen(3000, () => { server.listen(config.port, () => {
console.log("Started at https://localhost:3000") console.log(`Started at http${config.useHTTPS ? 's' : ''}://localhost:${config.port}`)
}) })