|
|
import express from 'express'; |
|
|
import cors from 'cors'; |
|
|
import fs from 'fs'; |
|
|
|
|
|
const app = express(); |
|
|
app.use(cors()); |
|
|
|
|
|
const read = (name) => JSON.parse(fs.readFileSync(new URL(`./data/${name}`, import.meta.url))); |
|
|
|
|
|
app.get('/api/services', (_req, res) => { |
|
|
const { category } = _req.query; |
|
|
let data = read('services.json'); |
|
|
|
|
|
|
|
|
if (category) { |
|
|
data = data.filter(service => service.category === category); |
|
|
} |
|
|
|
|
|
res.json(data); |
|
|
}); |
|
|
|
|
|
app.get('/api/icp-profiles', (_req, res) => { |
|
|
const { industry } = _req.query; |
|
|
let data = read('icp_profiles.json'); |
|
|
|
|
|
|
|
|
if (industry) { |
|
|
data = data.filter(profile => profile.industry === industry); |
|
|
} |
|
|
|
|
|
res.json(data); |
|
|
}); |
|
|
|
|
|
app.get('/api/case-studies', (_req, res) => { |
|
|
const { industry } = _req.query; |
|
|
let data = read('case_studies.json'); |
|
|
|
|
|
|
|
|
if (industry) { |
|
|
data = data.filter(study => study.industry === industry); |
|
|
} |
|
|
|
|
|
res.json(data); |
|
|
}); |
|
|
|
|
|
app.get('/api/frameworks', (_req, res) => { |
|
|
const { type } = _req.query; |
|
|
let data = read('frameworks.json'); |
|
|
|
|
|
|
|
|
if (type) { |
|
|
data = data.filter(framework => framework.type === type); |
|
|
} |
|
|
|
|
|
res.json(data); |
|
|
}); |
|
|
|
|
|
app.get('/api/articles', (_req, res) => { |
|
|
const { topic } = _req.query; |
|
|
let data = read('articles.json'); |
|
|
|
|
|
|
|
|
if (topic) { |
|
|
data = data.filter(article => article.topics.includes(topic)); |
|
|
} |
|
|
|
|
|
res.json(data); |
|
|
}); |
|
|
|
|
|
app.get('/api/categories', (_req, res) => { |
|
|
const { type } = _req.query; |
|
|
let data = read('category_labels.json'); |
|
|
|
|
|
|
|
|
if (type) { |
|
|
data = data.filter(category => category.type === type); |
|
|
} |
|
|
|
|
|
res.json(data); |
|
|
}); |
|
|
|
|
|
app.get('/api/metadata', (_req, res) => { |
|
|
const { version } = _req.query; |
|
|
let data = read('metadata.json'); |
|
|
|
|
|
|
|
|
if (version) { |
|
|
data = data.filter(meta => meta.version === version); |
|
|
} |
|
|
|
|
|
res.json(data); |
|
|
}); |
|
|
|
|
|
app.get('/api/faq', (_req, res) => { |
|
|
const data = read('test_data.json'); |
|
|
const faq = data.faq_sample || []; |
|
|
res.json(faq); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const PORT = process.env.PORT || 3000; |
|
|
app.listen(PORT, () => console.log(`NerdOptimize dataset API ready: http://localhost:${PORT}/api`)); |
|
|
|
|
|
|
|
|
|
|
|
|