Skip to content

Commit

Permalink
improve logging more
Browse files Browse the repository at this point in the history
  • Loading branch information
oscrx committed Apr 1, 2023
1 parent 6707f12 commit a92445e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "live-friend-locations-api",
"version": "1.0.2",
"version": "1.0.3",
"description": "A Friend tracker for Runelite",
"main": "server.js",
"scripts": {
Expand Down
14 changes: 9 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require("dotenv").config();
const randomstring = require("randomstring");
const fs = require("fs");
const app = express();
// https://expressjs.com/en/guide/behind-proxies.html
app.set('trust proxy', 'loopback, uniquelocal')
const port = process.env.PORT || 3000;

app.use(express.json());
Expand All @@ -28,11 +30,13 @@ if (!process.env.SHARED_KEY) {

app.use(function (req, res, next) {
if (!req.headers.authorization) {
console.log(`${req.ip} No credentials sent`)
return res.status(401).json({
error: "No credentials sent!",
error: "No credentials sent!",
});
}
if (req.headers.authorization != sharedKey) {
}
if (req.headers.authorization != sharedKey) {
console.log(`${req.ip} Wrong credentials`)
return res.status(403).json({
error: "Wrong credentials",
});
Expand All @@ -47,7 +51,7 @@ app.get("/", (req, res) => {
checkData(timestamp);

res.send(data);
console.log("Data requested")
console.log(`${req.ip} Data requested`)
});

// Receives Location Data
Expand All @@ -58,7 +62,7 @@ app.post("/post", (req, res) => {
updateData(newObj, timestamp);
checkData(timestamp);
res.send(data);
console.log("Data received")
console.log(`${req.ip} Data received: ${JSON.stringify(req.body)}`)
});

// Updates Location Data
Expand Down

0 comments on commit a92445e

Please sign in to comment.