Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,26 @@ Designed for use on iPads, laptops, or other devices commonly used by students.
- Includes **placeholder options** such as **Search**, **Contact**, **Recent**, and **Help**, which are non-functional and reserved for future implementation.
- Users can open and close the sidebar using the ☰ button on the top-left corner of the page.

## Setup
## Setup:

Clone the repository:
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.

1. Clone the repository:

- git clone [https://github.com/oss-slu/DigitalBonesBox.git](https://github.com/oss-slu/DigitalBonesBox.git)
- Open the project in your preferred code editor.
- Install the dependencies:
```bash
npm install
- Navigate to "boneset-api" folder and paste this in your code to run the server:
```bash
npm start
- When the server starts running, run the frontend by clicking "Go Live" using live server on the status bar:
- cd DigitalBonesBox

2. Install dependencies:
This command will install the necessary packages for both the root project and the boneset-api server.

- npm install && npm install --prefix boneset-api

3. Run the application:
This command will start both the backend API server and the frontend live server concurrently.

- npm start

Your browser should automatically open to the application.

## Contributing

Expand Down
134 changes: 124 additions & 10 deletions boneset-api/server.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,112 @@
//const express = require("express");
//const axios = require("axios");
//const cors = require("cors");
//const path = require('path'); // Added for consistency, though not strictly needed for this version
//
//const app = express();
//const PORT = process.env.PORT || 8000;
//
//app.use(cors());
//
//// --- Original GitHub URLs ---
//const GITHUB_REPO = "https://raw.githubusercontent.com/oss-slu/DigitalBonesBox/data/DataPelvis/";
//const BONESET_JSON_URL = `${GITHUB_REPO}boneset/bony_pelvis.json`;
//const BONES_DIR_URL = `${GITHUB_REPO}bones/`;
//
//// Helper function to fetch JSON from GitHub
//async function fetchJSON(url) {
// try {
// const response = await axios.get(url);
// return response.data;
// } catch (error) {
// console.error(`Failed to fetch ${url}:`, error.message);
// return null;
// }
//}
//
//// Home route (fixes "Cannot GET /" issue)
//app.get("/", (req, res) => {
// res.json({ message: "Welcome to the Boneset API (GitHub-Integrated)" });
//});
//
//// --- Original Combined Data Endpoint ---
//// This endpoint still provides the main data for the dropdowns
//app.get("/combined-data", async (req, res) => {
// try {
// const bonesetData = await fetchJSON(BONESET_JSON_URL);
// if (!bonesetData) return res.status(500).json({ error: "Failed to load boneset data" });
//
// const bonesets = [{ id: bonesetData.id, name: bonesetData.name }];
// const bones = [];
// const subbones = [];
//
// for (const boneId of bonesetData.bones) {
// const boneJsonUrl = `${BONES_DIR_URL}${boneId}.json`;
// const boneData = await fetchJSON(boneJsonUrl);
//
// if (boneData) {
// bones.push({ id: boneData.id, name: boneData.name, boneset: bonesetData.id });
// boneData.subBones.forEach(subBoneId => {
// subbones.push({ id: subBoneId, name: subBoneId.replace(/_/g, " "), bone: boneData.id });
// });
// }
// }
//
// res.json({ bonesets, bones, subbones });
//
// } catch (error) {
// console.error("Error fetching combined data:", error.message);
// res.status(500).json({ error: "Internal Server Error" });
// }
//});
//
//// --- NEW HTMX ENDPOINT ---
//// This endpoint fetches a description and returns it as an HTML fragment
//app.get("/api/description/", async (req, res) => { // Path changed here
// const { boneId } = req.query; // Changed from req.params to req.query
// if (!boneId) {
// return res.send(''); // Send empty response if no boneId is provided
// }
// const GITHUB_DESC_URL = `https://raw.githubusercontent.com/oss-slu/DigitalBonesBox/data/DataPelvis/descriptions/${boneId}_description.json`;
//
// try {
// const response = await axios.get(GITHUB_DESC_URL);
// const descriptionData = response.data;
//
// let html = `<li><strong>${descriptionData.name}</strong></li>`;
// descriptionData.description.forEach(point => {
// html += `<li>${point}</li>`;
// });
// res.send(html);
//
// } catch (error) {
// res.send('<li>Description not available.</li>');
// }
//});


// Start server
//app.listen(PORT, () => {
// console.log(`🚀 Server running on http://127.0.0.1:${PORT}`);
//});




const express = require("express");
const axios = require("axios");
const cors = require("cors");
const path = require('path');

Check failure on line 99 in boneset-api/server.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote

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

app.use(cors());

// Home route (fixes "Cannot GET /" issue)
app.get("/", (req, res) => {
res.json({ message: "Welcome to the Boneset API (GitHub-Integrated)" });
});

// GitHub raw URLs
const GITHUB_REPO = "https://raw.githubusercontent.com/oss-slu/DigitalBonesBox/data/DataPelvis/";
const BONESET_JSON_URL = `${GITHUB_REPO}boneset/bony_pelvis.json`;
const BONES_DIR_URL = `${GITHUB_REPO}bones/`;

// Fetch JSON helper function
async function fetchJSON(url) {
try {
const response = await axios.get(url);
Expand All @@ -28,7 +117,10 @@
}
}

// Combined data endpoint
app.get("/", (req, res) => {
res.json({ message: "Welcome to the Boneset API (GitHub-Integrated)" });
});

app.get("/combined-data", async (req, res) => {
try {
const bonesetData = await fetchJSON(BONESET_JSON_URL);
Expand Down Expand Up @@ -58,7 +150,29 @@
}
});

// Start server
// --- CORRECTED HTMX ENDPOINT ---
app.get("/api/description/", async (req, res) => { // Path changed here (no :boneId)
const { boneId } = req.query; // Changed from req.params to req.query
if (!boneId) {
return res.send(''); // Send empty response if no boneId is provided

Check failure on line 157 in boneset-api/server.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
}
const GITHUB_DESC_URL = `https://raw.githubusercontent.com/oss-slu/DigitalBonesBox/data/DataPelvis/descriptions/${boneId}_description.json`;

try {
const response = await axios.get(GITHUB_DESC_URL);
const descriptionData = response.data;

let html = `<li><strong>${descriptionData.name}</strong></li>`;
descriptionData.description.forEach(point => {
html += `<li>${point}</li>`;
});
res.send(html);

} catch (error) {
res.send('<li>Description not available.</li>');

Check failure on line 172 in boneset-api/server.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
}
});

app.listen(PORT, () => {
console.log(`🚀 Server running on http://127.0.0.1:${PORT}`);
});
});
Loading
Loading