feat: Add IPNS support
This commit is contained in:
35
server.js
35
server.js
@@ -3,7 +3,7 @@ const express = require('express');
|
||||
const morgan = require('morgan');
|
||||
const cors = require('cors');
|
||||
const path = require('path');
|
||||
const { resolveHandshake, clearCache } = require('./lib/handshake');
|
||||
const { resolveHandshake, clearCache, clearIpnsCache } = require('./lib/handshake');
|
||||
const { fetchFromIpfs } = require('./lib/ipfs');
|
||||
const { PORT } = require('./config');
|
||||
|
||||
@@ -534,6 +534,39 @@ app.get('/api/refresh/:domain', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// New API route to refresh IPNS cache specifically
|
||||
app.get('/api/refresh-ipns/:ipnsName', async (req, res) => {
|
||||
try {
|
||||
const ipnsName = req.params.ipnsName;
|
||||
|
||||
// Validate IPNS name format (basic validation)
|
||||
if (!ipnsName.match(/^[a-zA-Z0-9]+$/)) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: 'Invalid IPNS name format'
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`Refreshing IPNS cache for: ${ipnsName}`);
|
||||
// Clear IPNS cache
|
||||
clearIpnsCache(ipnsName);
|
||||
|
||||
// Return success response
|
||||
res.json({
|
||||
success: true,
|
||||
message: `IPNS cache refresh initiated for ${ipnsName}`,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('IPNS refresh error:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: 'Server error during IPNS refresh operation'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Catch-all route to handle SPA navigation
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
||||
|
||||
Reference in New Issue
Block a user