Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

32 enhance writing data #39

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
781d61d
[Task] #3 improve error handling, logger and added chalk
Type-Style Jan 25, 2024
6d84638
[Change] #3 nodemon to clear console when in dev mode
Type-Style Jan 25, 2024
63085ed
[!Task] #32 webhook creates folder and file based on date
Type-Style Jan 25, 2024
8873654
[Change] #35 relocated tests and refactor write, also added file check
Type-Style Jan 26, 2024
91fba3b
[Task] #18, installed helmet, configured self as CSP origin
Type-Style Jan 26, 2024
a22f970
[Fix] moved chalk out of dev dependency
Type-Style Jan 29, 2024
c779de6
[Task] #32 error logging and text output improvement, log string inst…
Type-Style Jan 29, 2024
8a5137d
[Task] #18 CSP Update to allow localhost for testing
Type-Style Jan 29, 2024
3e8dab1
[Fix] #3 debugging setup improvments
Type-Style Jan 29, 2024
ff7c287
[FIX] #10 Error Handling
Type-Style Jan 29, 2024
10391c5
[Task] #10 writing basic non calculated data to file
Type-Style Jan 29, 2024
552dc32
[Fix] #10 avoid Header Modification after sending the request
Type-Style Jan 30, 2024
7bfdced
[Task] #10 JSON Data pretty output
Type-Style Jan 30, 2024
0bee573
[Task] #32 update types to reflect subobjects of entry
Type-Style Jan 30, 2024
9e801fe
[Task] #10 write time
Type-Style Jan 30, 2024
b801af4
[Task] #32 added logging for time edgecases
Type-Style Jan 30, 2024
b7360b2
[Task] #10 output seconds
Type-Style Jan 30, 2024
4cd1c07
[Task] #10 calculate distance based on lat and lon
Type-Style Jan 30, 2024
f8799b2
[Task] #32 writing tests for time and distance
Type-Style Jan 30, 2024
e39b8a7
[Task] #32 change distance calculation to use pythagoras
Type-Style Jan 30, 2024
6393efc
[Task] #38 add favicon
Type-Style Jan 31, 2024
353817c
[Task] #32 time converted to seconds
Type-Style Jan 31, 2024
f7df2d8
[Taskk] #32 speed calculation and output and tests
Type-Style Jan 31, 2024
976096a
[Task] #32 speed tests
Type-Style Jan 31, 2024
e9d0bbe
[Task] #33 add ignore
Type-Style Jan 31, 2024
e97d965
[Task] #32 test finetuning
Type-Style Jan 31, 2024
1a89b42
[Task] #32 add angle between entries
Type-Style Jan 31, 2024
c346ffb
[Task] #32 test for angle, extracted getData function
Type-Style Jan 31, 2024
003e57d
[change] #32 test to include optional leading 0 for days
Type-Style Feb 1, 2024
dbbbb46
[!!!Task] #18 add uncaughtExeption handler as last resort
Type-Style Feb 1, 2024
50c9700
[Task] #7 enhance static options to include common filetypes; index …
Type-Style Feb 2, 2024
04e2761
[change] #32 validation to be used more explictly
Type-Style Feb 2, 2024
c0b9db6
[change] #32 add index to log while writing
Type-Style Feb 2, 2024
29cc03c
[Task] #32 test if 1000 calls can be made with randomized data
Type-Style Feb 2, 2024
1145e9e
[!!! Task] #32 limit JSON Data to be 1000 lines: replace last line wi…
Type-Style Feb 2, 2024
19aa8eb
[Change, Task] #32 if 1000 entries exceeded, only replace last if hdo…
Type-Style Feb 2, 2024
df0711c
[temp] test y tests fail
Type-Style Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
data/

# Logs
logs
*.log
Expand Down
32 changes: 13 additions & 19 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug server.ts",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\src\\app.ts",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
}
]
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug TypeScript",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\src\\app.ts",
"preLaunchTask": "build"
}
]
}
18 changes: 18 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "npx tsc -p tsconfig.json",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$tsc"
}
]
}
Binary file added httpdocs/favicon.ico
Binary file not shown.
5 changes: 4 additions & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"watch": ["src"],
"ext": ".ts",
"ignore": [],
"exec": "tsc && node dist/app.js"
"exec": "tsc && node dist/app.js",
"events": {
"start": "clear"
}
}
29 changes: 22 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@jest/globals": "^29.7.0",
"@tsconfig/node20": "^20.1.2",
"@types/bcrypt": "^5.0.2",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.21",
"@types/hpp": "^0.2.5",
"@types/jest": "^29.5.11",
Expand All @@ -35,8 +36,10 @@
"typescript": "^5.3.3"
},
"dependencies": {
"chalk": "^4.1.2",
"express": "^4.18.2",
"express-validator": "^7.0.1",
"helmet": "^7.1.0",
"hpp": "^0.2.3",
"module-alias": "^2.2.3"
},
Expand Down
15 changes: 13 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
require('module-alias/register');
import { config } from 'dotenv';
import express from 'express';
import helmet from 'helmet';
import hpp from 'hpp';
import cache from './cache';
import * as error from "./error";
import writeRouter from '@src/controller/write';
import path from 'path';
import logger from '@src/scripts/logger';


// configurations
config();
const app = express();
app.use(
helmet({
contentSecurityPolicy: {
directives: {
"default-src": "'self'",
"img-src": "*"
},
},
}),
);

app.use(hpp());
app.use(cache);

Expand All @@ -30,5 +41,5 @@ app.use(error.handler);

// init server
app.listen(80, () => {
logger.log(`Server running //localhost:80`);
logger.log(`Server running //localhost:80, ENV: ${process.env.NODE_ENV}`, true);
});
100 changes: 0 additions & 100 deletions src/controller/write.test.ts

This file was deleted.

27 changes: 17 additions & 10 deletions src/controller/write.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
import express, { Request, Response, NextFunction } from 'express';
import { entry } from '@src/models/entry';
import { validationResult } from 'express-validator';
import { create as createError } from '@src/error';


// example call: /write?user=xx&lat=00.000&lon=00.000&timestamp=1704063600000&hdop=0.0&altitude=0.000&speed=0.000&heading=000.0
function errorChecking (req:Request, res:Response, next:NextFunction) {
async function errorChecking (req:Request, res:Response, next:NextFunction) {
const errors = validationResult(req);
if (!errors.isEmpty()) {
const errorAsJson = { errors: errors.array()};
const errorAsString = new Error(JSON.stringify(errorAsJson));
const errorAsString = JSON.stringify(errorAsJson);
const hasKeyErrors = errors.array().some(error => error.msg.includes("Key"));

res.status(hasKeyErrors ? 403 : 422); // send forbidden or unprocessable content
return next(errorAsString);
// send forbidden or unprocessable content
return createError(res, hasKeyErrors ? 403 : 422, errorAsString, next)
}

if (req.method == "HEAD") {
res.status(200).end();
return;
}

// Regular Save logic from here

//entry.create(req, res);
//const test = process.env.TEST;
// res.send(req.query);

// Regular Save logic from here
await entry.create(req, res, next);

if (!res.locals.error) {
res.send(req.query);
} else {
/* at this point error handling already happend,
* or the request has already been send
* therefor there is no need for it again (only middleware to follow at this point) */
next();
}
}


Expand Down
Loading
Loading