Spaces:
Paused
Paused
File size: 1,598 Bytes
3b51fca eaf83d8 bd2145b 3b51fca eaf83d8 3b51fca eaf83d8 3b51fca bd2145b 3b51fca | 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 54 55 56 57 58 59 60 61 62 | const express = require('express');
const bodyParser = require('body-parser');
const { searchCatalog, getMeta, getStreams } = require('./handlers'); // Import the handlers
const addonManifest = require('./addon'); // Import the manifest
const app = express();
const port = 3000;
// Middleware to parse JSON bodies
app.use(bodyParser.json());
// Initialize the addon manifest
const manifest = addonManifest({
env: {
addonContentIdPrefix: 'archive-org',
},
});
// Define routes
app.get('/manifest.json', (req, res) => {
// Return the addon manifest
res.json(manifest);
});
app.post('/searchCatalog', async (req, res) => {
try {
const { type, id, extra } = req.body;
const response = await searchCatalog({ type, id, extra });
res.json(response);
} catch (error) {
console.error('Error in searchCatalog:', error);
res.status(500).send('Internal Server Error');
}
});
app.post('/getMeta', async (req, res) => {
try {
const { identifier } = req.body;
const meta = await getMeta({ identifier });
res.json(meta);
} catch (error) {
console.error('Error in getMeta:', error);
res.status(500).send('Internal Server Error');
}
});
app.post('/getStreams', async (req, res) => {
try {
const { identifier } = req.body;
const streams = await getStreams({ identifier });
res.json(streams);
} catch (error) {
console.error('Error in getStreams:', error);
res.status(500).send('Internal Server Error');
}
});
// Start the server
app.listen(port, () => {
console.log(`Server started on http://localhost:${port}`);
});
|