Skip to content

Commit 44cb0a7

Browse files
authored
Merge pull request #123 from oss-slu/codebase_cleanup
CodeBase Clean up
2 parents c38c037 + 7a1b351 commit 44cb0a7

File tree

11 files changed

+2645
-490
lines changed

11 files changed

+2645
-490
lines changed

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,26 @@ Designed for use on iPads, laptops, or other devices commonly used by students.
3636
- Includes **placeholder options** such as **Search**, **Contact**, **Recent**, and **Help**, which are non-functional and reserved for future implementation.
3737
- Users can open and close the sidebar using the ☰ button on the top-left corner of the page.
3838

39-
## Setup
39+
## Setup:
4040

41-
Clone the repository:
41+
To run this project locally, you will need to have Node.js installed. The application consists of a backend API and a frontend client, which can be run together with a single command.
42+
43+
1. Clone the repository:
4244

4345
- git clone [https://github.com/oss-slu/DigitalBonesBox.git](https://github.com/oss-slu/DigitalBonesBox.git)
44-
- Open the project in your preferred code editor.
45-
- Install the dependencies:
46-
```bash
47-
npm install
48-
- Navigate to "boneset-api" folder and paste this in your code to run the server:
49-
```bash
50-
npm start
51-
- When the server starts running, run the frontend by clicking "Go Live" using live server on the status bar:
46+
- cd DigitalBonesBox
47+
48+
2. Install dependencies:
49+
This command will install the necessary packages for both the root project and the boneset-api server.
50+
51+
- npm install && npm install --prefix boneset-api
52+
53+
3. Run the application:
54+
This command will start both the backend API server and the frontend live server concurrently.
55+
56+
- npm start
57+
58+
Your browser should automatically open to the application.
5259

5360
## Contributing
5461

boneset-api/server.js

Lines changed: 124 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,112 @@
1+
//const express = require("express");
2+
//const axios = require("axios");
3+
//const cors = require("cors");
4+
//const path = require('path'); // Added for consistency, though not strictly needed for this version
5+
//
6+
//const app = express();
7+
//const PORT = process.env.PORT || 8000;
8+
//
9+
//app.use(cors());
10+
//
11+
//// --- Original GitHub URLs ---
12+
//const GITHUB_REPO = "https://raw.githubusercontent.com/oss-slu/DigitalBonesBox/data/DataPelvis/";
13+
//const BONESET_JSON_URL = `${GITHUB_REPO}boneset/bony_pelvis.json`;
14+
//const BONES_DIR_URL = `${GITHUB_REPO}bones/`;
15+
//
16+
//// Helper function to fetch JSON from GitHub
17+
//async function fetchJSON(url) {
18+
// try {
19+
// const response = await axios.get(url);
20+
// return response.data;
21+
// } catch (error) {
22+
// console.error(`Failed to fetch ${url}:`, error.message);
23+
// return null;
24+
// }
25+
//}
26+
//
27+
//// Home route (fixes "Cannot GET /" issue)
28+
//app.get("/", (req, res) => {
29+
// res.json({ message: "Welcome to the Boneset API (GitHub-Integrated)" });
30+
//});
31+
//
32+
//// --- Original Combined Data Endpoint ---
33+
//// This endpoint still provides the main data for the dropdowns
34+
//app.get("/combined-data", async (req, res) => {
35+
// try {
36+
// const bonesetData = await fetchJSON(BONESET_JSON_URL);
37+
// if (!bonesetData) return res.status(500).json({ error: "Failed to load boneset data" });
38+
//
39+
// const bonesets = [{ id: bonesetData.id, name: bonesetData.name }];
40+
// const bones = [];
41+
// const subbones = [];
42+
//
43+
// for (const boneId of bonesetData.bones) {
44+
// const boneJsonUrl = `${BONES_DIR_URL}${boneId}.json`;
45+
// const boneData = await fetchJSON(boneJsonUrl);
46+
//
47+
// if (boneData) {
48+
// bones.push({ id: boneData.id, name: boneData.name, boneset: bonesetData.id });
49+
// boneData.subBones.forEach(subBoneId => {
50+
// subbones.push({ id: subBoneId, name: subBoneId.replace(/_/g, " "), bone: boneData.id });
51+
// });
52+
// }
53+
// }
54+
//
55+
// res.json({ bonesets, bones, subbones });
56+
//
57+
// } catch (error) {
58+
// console.error("Error fetching combined data:", error.message);
59+
// res.status(500).json({ error: "Internal Server Error" });
60+
// }
61+
//});
62+
//
63+
//// --- NEW HTMX ENDPOINT ---
64+
//// This endpoint fetches a description and returns it as an HTML fragment
65+
//app.get("/api/description/", async (req, res) => { // Path changed here
66+
// const { boneId } = req.query; // Changed from req.params to req.query
67+
// if (!boneId) {
68+
// return res.send(''); // Send empty response if no boneId is provided
69+
// }
70+
// const GITHUB_DESC_URL = `https://raw.githubusercontent.com/oss-slu/DigitalBonesBox/data/DataPelvis/descriptions/${boneId}_description.json`;
71+
//
72+
// try {
73+
// const response = await axios.get(GITHUB_DESC_URL);
74+
// const descriptionData = response.data;
75+
//
76+
// let html = `<li><strong>${descriptionData.name}</strong></li>`;
77+
// descriptionData.description.forEach(point => {
78+
// html += `<li>${point}</li>`;
79+
// });
80+
// res.send(html);
81+
//
82+
// } catch (error) {
83+
// res.send('<li>Description not available.</li>');
84+
// }
85+
//});
86+
87+
88+
// Start server
89+
//app.listen(PORT, () => {
90+
// console.log(`🚀 Server running on http://127.0.0.1:${PORT}`);
91+
//});
92+
93+
94+
95+
196
const express = require("express");
297
const axios = require("axios");
398
const cors = require("cors");
99+
const path = require('path');
4100

5101
const app = express();
6102
const PORT = process.env.PORT || 8000;
7103

8104
app.use(cors());
9105

10-
// Home route (fixes "Cannot GET /" issue)
11-
app.get("/", (req, res) => {
12-
res.json({ message: "Welcome to the Boneset API (GitHub-Integrated)" });
13-
});
14-
15-
// GitHub raw URLs
16106
const GITHUB_REPO = "https://raw.githubusercontent.com/oss-slu/DigitalBonesBox/data/DataPelvis/";
17107
const BONESET_JSON_URL = `${GITHUB_REPO}boneset/bony_pelvis.json`;
18108
const BONES_DIR_URL = `${GITHUB_REPO}bones/`;
19109

20-
// Fetch JSON helper function
21110
async function fetchJSON(url) {
22111
try {
23112
const response = await axios.get(url);
@@ -28,7 +117,10 @@ async function fetchJSON(url) {
28117
}
29118
}
30119

31-
// Combined data endpoint
120+
app.get("/", (req, res) => {
121+
res.json({ message: "Welcome to the Boneset API (GitHub-Integrated)" });
122+
});
123+
32124
app.get("/combined-data", async (req, res) => {
33125
try {
34126
const bonesetData = await fetchJSON(BONESET_JSON_URL);
@@ -58,7 +150,29 @@ app.get("/combined-data", async (req, res) => {
58150
}
59151
});
60152

61-
// Start server
153+
// --- CORRECTED HTMX ENDPOINT ---
154+
app.get("/api/description/", async (req, res) => { // Path changed here (no :boneId)
155+
const { boneId } = req.query; // Changed from req.params to req.query
156+
if (!boneId) {
157+
return res.send(''); // Send empty response if no boneId is provided
158+
}
159+
const GITHUB_DESC_URL = `https://raw.githubusercontent.com/oss-slu/DigitalBonesBox/data/DataPelvis/descriptions/${boneId}_description.json`;
160+
161+
try {
162+
const response = await axios.get(GITHUB_DESC_URL);
163+
const descriptionData = response.data;
164+
165+
let html = `<li><strong>${descriptionData.name}</strong></li>`;
166+
descriptionData.description.forEach(point => {
167+
html += `<li>${point}</li>`;
168+
});
169+
res.send(html);
170+
171+
} catch (error) {
172+
res.send('<li>Description not available.</li>');
173+
}
174+
});
175+
62176
app.listen(PORT, () => {
63177
console.log(`🚀 Server running on http://127.0.0.1:${PORT}`);
64-
});
178+
});

0 commit comments

Comments
 (0)