-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal-dev-server.js
More file actions
executable file
·53 lines (43 loc) · 1.74 KB
/
local-dev-server.js
File metadata and controls
executable file
·53 lines (43 loc) · 1.74 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
#!/usr/bin/env node
// Local development server to mock the Vercel serverless function
// Run this alongside Hugo server for local development
const http = require('http');
const fs = require('fs');
const path = require('path');
// Read config from config.local.toml
const configPath = path.join(__dirname, 'config.local.toml');
let config = {
pexelsApiKey: null,
formspreeEndpoint: null
};
try {
const configContent = fs.readFileSync(configPath, 'utf8');
// Simple TOML parsing for our specific config
const pexelsMatch = configContent.match(/pexels_api_key\s*=\s*"([^"]+)"/);
const formspreeMatch = configContent.match(/formspree_endpoint\s*=\s*"([^"]+)"/);
if (pexelsMatch) config.pexelsApiKey = pexelsMatch[1];
if (formspreeMatch) config.formspreeEndpoint = formspreeMatch[1];
console.log('✅ Loaded config from config.local.toml');
} catch (error) {
console.warn('⚠️ Could not read config.local.toml:', error.message);
}
const server = http.createServer((req, res) => {
// Enable CORS
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
if (req.url === '/api/config' && req.method === 'GET') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(config));
console.log('📡 Served config to client');
} else {
res.statusCode = 404;
res.end('Not found');
}
});
const PORT = 3001;
server.listen(PORT, () => {
console.log(`🚀 Local dev server running on http://localhost:${PORT}`);
console.log(`📡 API endpoint: http://localhost:${PORT}/api/config`);
console.log('💡 Update your pexels-config.html to use this endpoint for local development');
});