Add route to get stuff
This commit is contained in:
parent
aec4e84d4a
commit
0a5b3775a7
7
index.js
7
index.js
|
|
@ -37,6 +37,13 @@ app.use((req, res, next) => {
|
|||
next();
|
||||
})
|
||||
|
||||
global.auth = (req, res, next) => {
|
||||
if (process.env.API_KEY && req.headers['Authorization'] === process.env.API_KEY) {
|
||||
return next();
|
||||
}
|
||||
return res.status(401).json({ error: 'Unauthorized' });
|
||||
}
|
||||
|
||||
// Load routes from routes/* recursively
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
|
|
|||
15
routes/api/getAll.js
Normal file
15
routes/api/getAll.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const db = global.db;
|
||||
|
||||
router.get("/", global.auth, async (req, res) => {
|
||||
db.all("SELECT * FROM analytics", [], (err, rows) => {
|
||||
if (err) {
|
||||
console.error('Failed to retrieve analytics data', err);
|
||||
return res.status(500).json({ error: 'Database error' });
|
||||
}
|
||||
return res.status(200).json({ data: rows });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
@ -2,7 +2,7 @@ const express = require('express');
|
|||
const router = express.Router();
|
||||
const db = global.db;
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
router.post('/', global.auth, async (req, res) => {
|
||||
const { serverId, totalPlayers, currentPlayers, duration } = req.body;
|
||||
if (!serverId || totalPlayers === undefined || currentPlayers === undefined || duration === undefined) {
|
||||
return res.status(400).json({ error: 'Missing required fields' });
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const express = require('express');
|
|||
const router = express.Router();
|
||||
const db = global.db;
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
router.post('/', global.auth, async (req, res) => {
|
||||
const { serverId, serverStartTime, revision, placeId} = req.body;
|
||||
console.log('Received startup data:', req.body);
|
||||
if (serverId === undefined || serverStartTime === undefined || revision === undefined || placeId === undefined) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue