+
+
+ `;
+ sendHTML(res, 200, html);
+ }
+
+ else if (pathname === '/api/articles' && method === 'GET') {
+ // Get all articles
+ sendJSON(res, 200, {
+ success: true,
+ count: knowledgeBase.length,
+ data: knowledgeBase
+ });
+ }
+
+ else if (pathname.match(/^\/api\/articles\/\d+$/) && method === 'GET') {
+ // Get single article
+ const id = parseInt(pathname.split('/')[3]);
+ const article = knowledgeBase.find(a => a.id === id);
+
+ if (article) {
+ sendJSON(res, 200, { success: true, data: article });
+ } else {
+ sendJSON(res, 404, { success: false, error: 'Article not found' });
+ }
+ }
+
+ else if (pathname === '/api/articles' && method === 'POST') {
+ // Create new article
+ let body = '';
+ req.on('data', chunk => {
+ body += chunk.toString();
+ });
+ req.on('end', () => {
+ try {
+ const newArticle = JSON.parse(body);
+ newArticle.id = nextId++;
+ newArticle.author = newArticle.author || 'ๅฟๅ';
+ knowledgeBase.push(newArticle);
+ sendJSON(res, 201, {
+ success: true,
+ message: 'Article created successfully',
+ data: newArticle
+ });
+ } catch (error) {
+ sendJSON(res, 400, { success: false, error: 'Invalid JSON' });
+ }
+ });
+ }
+
+ else if (pathname === '/api/stats' && method === 'GET') {
+ // Get platform statistics
+ const stats = {
+ totalArticles: knowledgeBase.length,
+ categories: [...new Set(knowledgeBase.map(a => a.category))],
+ highImpactArticles: knowledgeBase.filter(a => a.impact === '้ซ' || a.impact === 'ๅ ณ้ฎ').length,
+ mission: "Democratizing knowledge to transform the world"
+ };
+ sendJSON(res, 200, { success: true, data: stats });
+ }
+
+ else {
+ sendJSON(res, 404, { success: false, error: 'Endpoint not found' });
+ }
+}
+
+// Create and start server
+const server = http.createServer(handleRequest);
+
+server.listen(PORT, HOST, () => {
+ console.log('');
+ console.log('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
+ console.log('๐ Transform World - Knowledge Sharing Platform');
+ console.log('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
+ console.log('');
+ console.log(`โ Server is running on http://${HOST}:${PORT}`);
+ console.log('');
+ console.log('๐ฑ Access the platform:');
+ console.log(` Web Interface: http://localhost:${PORT}/`);
+ console.log(` API Endpoint: http://localhost:${PORT}/api/articles`);
+ console.log('');
+ console.log('๐ก This platform enables:');
+ console.log(' โข Knowledge sharing across borders');
+ console.log(' โข Collaborative learning');
+ console.log(' โข Democratized education');
+ console.log(' โข Community-driven content');
+ console.log('');
+ console.log('๐ Press Ctrl+C to stop the server');
+ console.log('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
+ console.log('');
+});
+
+// Handle graceful shutdown
+process.on('SIGTERM', () => {
+ console.log('\n\n๐ Shutting down gracefully...');
+ server.close(() => {
+ console.log('โ Server closed');
+ process.exit(0);
+ });
+});
+
+process.on('SIGINT', () => {
+ console.log('\n\n๐ Shutting down gracefully...');
+ server.close(() => {
+ console.log('โ Server closed');
+ process.exit(0);
+ });
+});
From f1c572ef668dd25b8936c8c0cf66d6c20ec2f169 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 2 Feb 2026 09:25:23 +0000
Subject: [PATCH 3/4] Add security improvements: input validation and DoS
protection
Co-authored-by: donglovejava <211940267+donglovejava@users.noreply.github.com>
---
README.md | 4 ++--
src/app.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index e9208fd..b01437f 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
> **"็ฅ่ฏๆฏๆนๅไธ็ๆๅผบๅคง็ๅทฅๅ ท"** | *"Knowledge is the most powerful tool to transform the world"*
[](https://opensource.org/licenses/MIT)
-[](https://nodejs.org/)
+[](https://nodejs.org/)
## ๐ฏ Vision | ๆฟๆฏ
@@ -28,7 +28,7 @@ Transform World is an open-source knowledge-sharing platform that democratizes e
## ๐ Quick Start
### Prerequisites
-- Node.js (v12.0.0 or higher)
+- Node.js (v18.0.0 or higher - LTS version recommended)
- No external dependencies required - uses built-in Node.js modules!
### Installation & Running
diff --git a/src/app.js b/src/app.js
index 2e85049..c46e1b6 100644
--- a/src/app.js
+++ b/src/app.js
@@ -40,6 +40,13 @@ const knowledgeBase = [
let nextId = 4;
+// Constants
+const MAX_BODY_SIZE = 1024 * 1024; // 1MB limit for request body
+const IMPACT_LEVELS = {
+ HIGH: '้ซ',
+ CRITICAL: 'ๅ ณ้ฎ'
+};
+
// Server configuration
const PORT = process.env.PORT || 3000;
const HOST = process.env.HOST || '0.0.0.0';
@@ -334,14 +341,52 @@ function handleRequest(req, res) {
else if (pathname === '/api/articles' && method === 'POST') {
// Create new article
let body = '';
+ let bodySize = 0;
+
req.on('data', chunk => {
+ bodySize += chunk.length;
+
+ // Prevent memory exhaustion attacks
+ if (bodySize > MAX_BODY_SIZE) {
+ res.writeHead(413, { 'Content-Type': 'application/json; charset=utf-8' });
+ res.end(JSON.stringify({ success: false, error: 'Request body too large' }));
+ req.destroy();
+ return;
+ }
+
body += chunk.toString();
});
+
req.on('end', () => {
try {
const newArticle = JSON.parse(body);
+
+ // Validate required fields
+ if (!newArticle.title || typeof newArticle.title !== 'string' || newArticle.title.trim() === '') {
+ sendJSON(res, 400, { success: false, error: 'Title is required and must be a non-empty string' });
+ return;
+ }
+ if (!newArticle.content || typeof newArticle.content !== 'string' || newArticle.content.trim() === '') {
+ sendJSON(res, 400, { success: false, error: 'Content is required and must be a non-empty string' });
+ return;
+ }
+ if (!newArticle.category || typeof newArticle.category !== 'string' || newArticle.category.trim() === '') {
+ sendJSON(res, 400, { success: false, error: 'Category is required and must be a non-empty string' });
+ return;
+ }
+ if (!newArticle.impact || typeof newArticle.impact !== 'string' || newArticle.impact.trim() === '') {
+ sendJSON(res, 400, { success: false, error: 'Impact is required and must be a non-empty string' });
+ return;
+ }
+
+ // Sanitize inputs
+ newArticle.title = newArticle.title.trim();
+ newArticle.content = newArticle.content.trim();
+ newArticle.category = newArticle.category.trim();
+ newArticle.impact = newArticle.impact.trim();
+
newArticle.id = nextId++;
- newArticle.author = newArticle.author || 'ๅฟๅ';
+ newArticle.author = newArticle.author?.trim() || 'ๅฟๅ';
knowledgeBase.push(newArticle);
sendJSON(res, 201, {
success: true,
@@ -359,7 +404,9 @@ function handleRequest(req, res) {
const stats = {
totalArticles: knowledgeBase.length,
categories: [...new Set(knowledgeBase.map(a => a.category))],
- highImpactArticles: knowledgeBase.filter(a => a.impact === '้ซ' || a.impact === 'ๅ ณ้ฎ').length,
+ highImpactArticles: knowledgeBase.filter(a =>
+ a.impact === IMPACT_LEVELS.HIGH || a.impact === IMPACT_LEVELS.CRITICAL
+ ).length,
mission: "Democratizing knowledge to transform the world"
};
sendJSON(res, 200, { success: true, data: stats });
From 5c1b948722d825f9bdc872cec7b3ddedadb5a91e Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 2 Feb 2026 09:27:07 +0000
Subject: [PATCH 4/4] Complete API documentation and enforce Node.js version
Co-authored-by: donglovejava <211940267+donglovejava@users.noreply.github.com>
---
README.md | 16 ++++++++++++++--
package.json | 3 +++
src/app.js | 15 ++++++++++++++-
3 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index b01437f..cdf1a75 100644
--- a/README.md
+++ b/README.md
@@ -90,17 +90,29 @@ curl http://localhost:3000/api/articles
# Get platform statistics
curl http://localhost:3000/api/stats
-# Create a new article
+# Create new article
curl -X POST http://localhost:3000/api/articles \
-H "Content-Type: application/json" \
-d '{
"title": "ๆฐ็ฅ่ฏๅไบซ",
"content": "่ฟๆฏไธไธชๆนๅไธ็็ๆณๆณ...",
"category": "ๅๆฐ",
- "impact": "้ซ"
+ "impact": "้ซ",
+ "author": "Your Name (optional, defaults to ๅฟๅ)"
}'
```
+### API Request Requirements
+
+**POST /api/articles** requires:
+- `title` (string, required): Article title
+- `content` (string, required): Article content
+- `category` (string, required): Article category
+- `impact` (string, required): Must be either "้ซ" (High) or "ๅ ณ้ฎ" (Critical)
+- `author` (string, optional): Author name, defaults to "ๅฟๅ" (Anonymous) if not provided
+
+All string fields will be trimmed of whitespace. Maximum request body size is 1MB.
+
## ๐ Core Concepts
### Knowledge Categories
diff --git a/package.json b/package.json
index 6bc4b6d..9bb2ef4 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,9 @@
"start": "node src/app.js",
"dev": "node src/app.js"
},
+ "engines": {
+ "node": ">=18.0.0"
+ },
"keywords": [
"education",
"knowledge-sharing",
diff --git a/src/app.js b/src/app.js
index c46e1b6..1a4ab5a 100644
--- a/src/app.js
+++ b/src/app.js
@@ -46,6 +46,7 @@ const IMPACT_LEVELS = {
HIGH: '้ซ',
CRITICAL: 'ๅ ณ้ฎ'
};
+const VALID_IMPACT_VALUES = [IMPACT_LEVELS.HIGH, IMPACT_LEVELS.CRITICAL];
// Server configuration
const PORT = process.env.PORT || 3000;
@@ -297,7 +298,10 @@ function handleRequest(req, res) {
ๅผๅ่ ๅฏไปฅไฝฟ็จไปฅไธ API ๆฅ้ๆ็ฅ่ฏๅนณๅฐ๏ผ
GET /api/articles - ่ทๅๆๆๆ็ซ
GET /api/articles/:id - ่ทๅๆๅฎๆ็ซ
-
POST /api/articles - ๅๅปบๆฐๆ็ซ
+
POST /api/articles - ๅๅปบๆฐๆ็ซ
+ Required fields: title, content, category, impact (้ซ or ๅ ณ้ฎ)
+ Optional: author (defaults to ๅฟๅ if not provided)
+