studyup 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "studyup",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "StudyUp Game Portal",
5
5
  "main": "index.html",
6
6
  "scripts": {
package/server.js ADDED
@@ -0,0 +1,50 @@
1
+ const express = require('express');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ const app = express();
6
+ const PORT = process.env.PORT || 3000;
7
+ const DATA_FILE = path.join(__dirname, 'data.json');
8
+
9
+ app.use(express.json());
10
+ // Serve static files from the same root folder where server.js lives
11
+ app.use(express.static(__dirname));
12
+
13
+ // Helper to read data
14
+ function getData() {
15
+ if (!fs.existsSync(DATA_FILE)) {
16
+ const defaultData = {
17
+ globalBlock: false,
18
+ codes: {
19
+ "123456": { games: ["Sandboxels", "HexGL", "ClassiCube", "2048"] }
20
+ }
21
+ };
22
+ fs.writeFileSync(DATA_FILE, JSON.stringify(defaultData, null, 2));
23
+ return defaultData;
24
+ }
25
+ return JSON.parse(fs.readFileSync(DATA_FILE, 'utf8'));
26
+ }
27
+
28
+ // Helper to write data
29
+ function saveData(data) {
30
+ fs.writeFileSync(DATA_FILE, JSON.stringify(data, null, 2));
31
+ }
32
+
33
+ // API: Get current config
34
+ app.get('/api/config', (req, res) => {
35
+ res.json(getData());
36
+ });
37
+
38
+ // API: Save/Update config (Admin actions)
39
+ app.post('/api/config', (req, res) => {
40
+ try {
41
+ saveData(req.body);
42
+ res.json({ success: true });
43
+ } catch (err) {
44
+ res.status(500).json({ success: false, error: err.message });
45
+ }
46
+ });
47
+
48
+ app.listen(PORT, () => {
49
+ console.log(`StudyUp server running on port ${PORT}`);
50
+ });