Added port option in config.json

This commit is contained in:
Adrian Victor 2024-11-16 15:32:56 -03:00
commit 7455199177
3 changed files with 9 additions and 5 deletions

3
.gitignore vendored
View file

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

View file

@ -5,7 +5,7 @@
"version": "1.0.0",
"private": false,
"scripts": {
"start": "ts-node main.ts",
"start": "ts-node zephyrus.ts",
"build" : "npx tsc"
},
"devDependencies": {

View file

@ -24,7 +24,8 @@ function requestHandler(request: IncomingMessage, response: ServerResponse) {
const path_ = decodeURI(parsed.pathname || '/');
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;
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.') {
if (log) {
@ -125,6 +126,6 @@ function requestHandler(request: IncomingMessage, response: ServerResponse) {
})
}
server.listen(3000, () => {
console.log("Started at https://localhost:3000")
server.listen(config.port, () => {
console.log(`Started at http${config.useHTTPS ? 's' : ''}://localhost:${config.port}`)
})