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+
196const express = require ( "express" ) ;
297const axios = require ( "axios" ) ;
398const cors = require ( "cors" ) ;
99+ const path = require ( 'path' ) ;
4100
5101const app = express ( ) ;
6102const PORT = process . env . PORT || 8000 ;
7103
8104app . 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
16106const GITHUB_REPO = "https://raw.githubusercontent.com/oss-slu/DigitalBonesBox/data/DataPelvis/" ;
17107const BONESET_JSON_URL = `${ GITHUB_REPO } boneset/bony_pelvis.json` ;
18108const BONES_DIR_URL = `${ GITHUB_REPO } bones/` ;
19109
20- // Fetch JSON helper function
21110async 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+
32124app . 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+
62176app . listen ( PORT , ( ) => {
63177 console . log ( `🚀 Server running on http://127.0.0.1:${ PORT } ` ) ;
64- } ) ;
178+ } ) ;
0 commit comments