Odstranit server.js
This commit is contained in:
62
server.js
62
server.js
@ -1,62 +0,0 @@
|
||||
// Node.js API server to fetch and merge Slovak company data by IČO
|
||||
// from two Finančná správa SR API endpoints
|
||||
|
||||
const express = require("express");
|
||||
const axios = require("axios");
|
||||
|
||||
const app = express();
|
||||
const PORT = 3000;
|
||||
|
||||
// Insert your API key below
|
||||
const API_KEY = "2t5lK487ces7Rc4oEHrIwCjB5DpoZUBChQxCLBiSrwGNdEubKpraAtQLEiJmPXkdjNw5FssYpuO0LXSZpk3U6oqePyFaIGHokg4WNPEM0302X2BK4iXpkFv9Qg7jyeUXh50bWVExVrVSBuOnOQpBzzdJ1k1D54b115MD3y5ticWxvGDLUaqLQgA6nzFgbYOx6dR0ToJUxU714TetLBZCBy0xKSnBaOrxYv10I1gZ1q4rQx4Q8k7BTR6MaP";
|
||||
|
||||
// API endpoint: /api/lookup?ico=XXXXXXXX
|
||||
app.get("/api/lookup", async (req, res) => {
|
||||
const ico = req.query.ico;
|
||||
|
||||
if (!ico) {
|
||||
return res.status(400).json({ error: "Missing ICO parameter" });
|
||||
}
|
||||
|
||||
const endpoints = [
|
||||
`https://iz.opendata.financnasprava.sk/api/data/ds_dsrdp/search?page=1&column=ico&search=${ico}`,
|
||||
`https://iz.opendata.financnasprava.sk/api/data/ds_dphs/search?page=1&column=ico&search=${ico}`
|
||||
];
|
||||
|
||||
try {
|
||||
// Fetch both endpoints in parallel
|
||||
const [res1, res2] = await Promise.all(endpoints.map(url =>
|
||||
axios.get(url, {
|
||||
headers: {
|
||||
accept: "application/json",
|
||||
key: API_KEY
|
||||
}
|
||||
})
|
||||
));
|
||||
|
||||
const data1 = res1.data?.data || [];
|
||||
const data2 = res2.data?.data || [];
|
||||
|
||||
// Combine and deduplicate by IČO or ID if available
|
||||
const merged = [...data1, ...data2].filter(
|
||||
(item, index, self) =>
|
||||
index === self.findIndex((t) =>
|
||||
JSON.stringify(t) === JSON.stringify(item)
|
||||
)
|
||||
);
|
||||
|
||||
// Return merged, deduplicated result
|
||||
res.json({
|
||||
source1_count: data1.length,
|
||||
source2_count: data2.length,
|
||||
merged_count: merged.length,
|
||||
data: merged
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`API server running at http://localhost:${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user