File size: 3,834 Bytes
e476154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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;  // รับค่าจาก query parameter 'category'
  let data = read('services.json');  // อ่านข้อมูลจาก services.json
  
  // ถ้ามีการกรอง 'category' ให้กรองข้อมูล
  if (category) {
    data = data.filter(service => service.category === category);
  }

  res.json(data);
});

app.get('/api/icp-profiles', (_req, res) => {
  const { industry } = _req.query;  // รับค่าจาก query parameter 'industry'
  let data = read('icp_profiles.json');  // อ่านข้อมูลจาก icp_profiles.json
  
  // ถ้ามีการกรอง 'industry' ให้กรองข้อมูล
  if (industry) {
    data = data.filter(profile => profile.industry === industry);
  }

  res.json(data);
});

app.get('/api/case-studies', (_req, res) => {
  const { industry } = _req.query;  // รับค่าจาก query parameter 'industry'
  let data = read('case_studies.json');  // อ่านข้อมูลจาก case_studies.json
  
  // ถ้ามีการกรอง 'industry' ให้กรองข้อมูล
  if (industry) {
    data = data.filter(study => study.industry === industry);
  }

  res.json(data);
});

app.get('/api/frameworks', (_req, res) => {
  const { type } = _req.query;  // ตัวอย่าง ถ้าต้องการกรองตามประเภทของ framework
  let data = read('frameworks.json');  // อ่านข้อมูลจาก frameworks.json
  
  // ถ้ามีการกรอง 'type' ให้กรองข้อมูล
  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');  // อ่านข้อมูลจาก articles.json
  
  // ถ้ามีการกรอง 'topic' ให้กรองข้อมูล
  if (topic) {
    data = data.filter(article => article.topics.includes(topic));
  }

  res.json(data);
});

app.get('/api/categories', (_req, res) => {
  const { type } = _req.query;  // ตัวอย่าง ถ้าต้องการกรองตามประเภทของ category
  let data = read('category_labels.json');  // อ่านข้อมูลจาก category_labels.json
  
  // ถ้ามีการกรอง 'type' ให้กรองข้อมูล
  if (type) {
    data = data.filter(category => category.type === type);
  }

  res.json(data);
});

app.get('/api/metadata', (_req, res) => {
  const { version } = _req.query;  // ตัวอย่าง ถ้าต้องการกรองตาม version ของ metadata
  let data = read('metadata.json');  // อ่านข้อมูลจาก metadata.json
  
  // ถ้ามีการกรอง 'version' ให้กรองข้อมูล
  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 || [];  // ดึง faq_sample จาก test_data.json
  res.json(faq);
});



const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`NerdOptimize dataset API ready: http://localhost:${PORT}/api`));