lbry-desktop/src/platforms/electron/startSandbox.js

33 lines
896 B
JavaScript
Raw Normal View History

2019-03-15 02:54:17 +01:00
import express from 'express';
import unpackByOutpoint from './unpackByOutpoint';
2019-03-05 05:46:57 +01:00
2019-03-15 02:54:17 +01:00
// Polyfills and `lbry-redux`
global.fetch = require('node-fetch');
global.window = global;
if (typeof(global.fetch) === 'object') {
global.fetch = global.fetch.default;
}
2019-03-05 05:46:57 +01:00
2019-03-15 02:54:17 +01:00
// eslint-disable-next-line import/no-commonjs,global-require
const { Lbry } = require('lbry-redux');
2019-03-05 05:46:57 +01:00
2019-03-15 02:54:17 +01:00
delete global.window;
2019-03-05 05:46:57 +01:00
2019-03-15 02:54:17 +01:00
export default async function startSandbox() {
const sandbox = express();
const port = 5278;
2019-03-05 05:46:57 +01:00
2019-03-15 02:54:17 +01:00
sandbox.get('/set/:outpoint', async (req, res) => {
const { outpoint } = req.params;
2019-03-05 05:46:57 +01:00
2019-03-15 02:54:17 +01:00
const resolvedPath = await unpackByOutpoint(Lbry, outpoint);
2019-03-05 05:46:57 +01:00
2019-03-15 02:54:17 +01:00
sandbox.use(`/sandbox/${outpoint}/`, express.static(resolvedPath));
2019-03-05 05:46:57 +01:00
2019-03-15 02:54:17 +01:00
res.send(`/sandbox/${outpoint}/`);
});
// eslint-disable-next-line no-console
sandbox.listen(port, 'localhost', () => console.log(`Sandbox listening on port ${port}.`));
}