Internet_Archive / index.js
mikmc's picture
Update index.js
eaf83d8 verified
Raw History Blame Contribute Delete
1.6 kB
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}`);
});