32 lines
799 B
JSON
32 lines
799 B
JSON
const express = require('express');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
app.get('/nostr.json', (req, res) => {
|
|
const name = req.query.name;
|
|
fs.readFile(path.join(__dirname, 'data', 'nostr.json'), (err, data) => {
|
|
if (err) {
|
|
console.error(err);
|
|
res.status(500).send('Internal Server Error');
|
|
return;
|
|
}
|
|
const nostrJson = JSON.parse(data);
|
|
if (name && nostrJson.names.hasOwnProperty(name)) {
|
|
const filteredJson = {
|
|
"names": {
|
|
[name]: nostrJson.names[name]
|
|
}
|
|
};
|
|
res.json(filteredJson);
|
|
} else {
|
|
res.status(404).send('Not found');
|
|
}
|
|
});
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Server is running on port ${PORT}`);
|
|
});
|