mirror of
https://github.com/jason5ng32/MyIP.git
synced 2026-11-04 08:55:47 +00:00
common/ had become the backend's library: 30 of its 41 modules were imported by nothing in the frontend, so the name no longer said what belonged there. It now holds only what the frontend or the build imports too; backend-only code moved to server/, flat except for datasets/ (the dataset engine and its readers). The *-db/ dataset directories stay in common/: self-hosting docs and Docker volumes mount those paths. frontend/utils/ keeps its app-wide modules at the root and gains ip/ (IP / ASN shaping and validation), report/ (the report pipeline) and features/ (the pure layer of a single feature). Paths only — no logic changes. The Dockerfile copies server/, and the AGENTS.md files say where a new module goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
import { fetchUpstream } from '../common/fetch-with-timeout.js';
|
|
import logger from '../server/logger.js';
|
|
|
|
export default async (req, res) => {
|
|
// defensive; app.put() in backend-server.js already gates method
|
|
if (req.method !== 'PUT') {
|
|
return res.status(405).json({ error: 'Method not allowed' });
|
|
}
|
|
|
|
const key = process.env.IPCHECKING_API_KEY;
|
|
|
|
if (!key) {
|
|
return res.status(500).json({ error: 'API key is missing' });
|
|
}
|
|
|
|
const achievement = req.body;
|
|
if (!achievement) {
|
|
return res.status(400).json({ error: 'Achievement name is required' });
|
|
}
|
|
|
|
// Build request
|
|
const apiEndpoint = process.env.IPCHECKING_API_ENDPOINT;
|
|
const url = new URL(`${apiEndpoint}/updateuserachievements?key=${key}`);
|
|
|
|
try {
|
|
const apiResponse = await fetchUpstream(url, {
|
|
method: 'PUT',
|
|
headers: {
|
|
...req.headers,
|
|
},
|
|
body: JSON.stringify(req.body),
|
|
});
|
|
|
|
if (!apiResponse.ok) {
|
|
throw new Error(`API responded with status: ${apiResponse.status}`);
|
|
}
|
|
|
|
const data = await apiResponse.json();
|
|
res.json(data);
|
|
} catch (error) {
|
|
logger.error({ err: error }, 'update-user-achievement upstream request failed');
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
|
|
} |