Skip to content

Commit

Permalink
feat: added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
tts-jwiebe committed Jul 13, 2023
1 parent 130bc67 commit 99774d5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ jobs:
"md": "text/markdown"
}
-
run: node .github/test-default.js
run: |
node .github/test-default.js
cat log.txt
test-index-files:
strategy:
Expand All @@ -50,7 +52,9 @@ jobs:
index-files: |
["PULL_REQUEST_TEMPLATE.md"]
-
run: node .github/test-index-files.js
run: |
node .github/test-index-files.js
cat log.txt
test-allowed-methods:
strategy:
Expand All @@ -73,7 +77,9 @@ jobs:
allowed-methods: |
["POST"]
-
run: node .github/test-allowed-methods.js
run: |
node .github/test-allowed-methods.js
cat log.txt
# draft your next release notes as pull requests are merged into "master"
# the configuration is at /.github/release-drafter.yml.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,7 @@ steps:
"xml": "text/xml"
}
-
run: curl -vvvv http://localhost:8080/index.html
run: |
curl -vvvv http://localhost:8080/index.html
cat log.txt
```
21 changes: 19 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,24 @@ function deploy(config, ready) {
return path.posix.join(...url.split(path.sep));
}

let logger = fs.createWriteStream('log.txt', {
flags: 'a'
});
let writeLine = (line) => logger.write(`\n${line}`);

server.on('request', (request, response) => {
let now = new Date().toLocaleTimeString();
let data = '';

request.on('data', (chunk) => {
data += chunk;
});

request.on('end', () => {
writeLine(`[${now}] ${request.method} ${request.url} ${JSON.stringify(data)}`);
})


if (config.noCache) {
response.setHeader(
'Cache-Control',
Expand Down Expand Up @@ -84,15 +101,15 @@ function deploy(config, ready) {
}
const noIndexFound = config.indexFiles.every(elem => {
const indexFile = requestedFile + elem;
if(fs.existsSync(indexFile)){
if (fs.existsSync(indexFile)) {
requestedFile = indexFile;
stat = fs.statSync(requestedFile);
return false;
}
return true;
});

if(noIndexFound) {
if (noIndexFound) {
response.writeHead(200, {
'Content-Type': 'text/html'
});
Expand Down

0 comments on commit 99774d5

Please sign in to comment.