-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstub-server.js
More file actions
67 lines (57 loc) · 2.05 KB
/
Copy pathstub-server.js
File metadata and controls
67 lines (57 loc) · 2.05 KB
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
/**
* Stub server for DIG Network Extension
* This is a simple Node.js server that serves placeholder responses
* Run this with: node stub-server.js
*/
const http = require('http');
const url = require('url');
const path = require('path');
const PORT = 8080;
// Placeholder image (1x1 transparent PNG)
const PLACEHOLDER_IMAGE = Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==',
'base64'
);
const server = http.createServer((req, res) => {
const parsedUrl = url.parse(req.url, true);
const pathname = parsedUrl.pathname;
const ext = path.extname(pathname).toLowerCase();
// Determine if it's an image request
const isImage = ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.svg', '.ico', '.bmp'].includes(ext);
if (isImage) {
// Return placeholder image
res.writeHead(200, {
'Content-Type': 'image/png',
'Content-Length': PLACEHOLDER_IMAGE.length,
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'no-cache'
});
res.end(PLACEHOLDER_IMAGE);
} else {
// Return placeholder JSON/text response
const placeholderResponse = JSON.stringify({
message: 'DIG Network Extension - Stub Response',
path: pathname,
timestamp: new Date().toISOString(),
note: 'This is a placeholder response. The actual server implementation will be added later.'
});
res.writeHead(200, {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(placeholderResponse),
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'no-cache'
});
res.end(placeholderResponse);
}
});
server.listen(PORT, () => {
console.log(`DIG Network stub server running on http://localhost:${PORT}`);
console.log('This server will serve placeholder responses for chia:// protocol requests.');
});
server.on('error', (err) => {
if (err.code === 'EADDRINUSE') {
console.error(`Port ${PORT} is already in use. Please stop the other service or change the port.`);
} else {
console.error('Server error:', err);
}
});