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;
|
2019-03-18 06:09:50 +01:00
|
|
|
if (typeof global.fetch === 'object') {
|
2019-03-15 02:54:17 +01:00
|
|
|
global.fetch = global.fetch.default;
|
|
|
|
}
|
2019-03-05 05:46:57 +01:00
|
|
|
|
2021-10-17 10:36:14 +02:00
|
|
|
const Lbry = require('lbry');
|
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 port = 5278;
|
2019-03-19 05:01:59 +01:00
|
|
|
const sandbox = express();
|
2019-03-05 05:46:57 +01:00
|
|
|
|
2019-03-25 07:18:22 +01:00
|
|
|
sandbox.get('/set/:outpoint', async (req, res) => {
|
2019-03-15 02:54:17 +01:00
|
|
|
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}/`);
|
|
|
|
});
|
|
|
|
|
2019-03-19 05:01:59 +01:00
|
|
|
sandbox
|
|
|
|
.listen(port, 'localhost', () => console.log(`Sandbox listening on port ${port}.`))
|
|
|
|
.on('error', err => {
|
|
|
|
if (err.code === 'EADDRINUSE') {
|
|
|
|
console.log(
|
2019-10-28 22:09:01 +01:00
|
|
|
`Server already listening at localhost:${port}. This is probably another LBRY app running. If not, games in the app will not work.`
|
2019-03-19 05:01:59 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2019-03-15 02:54:17 +01:00
|
|
|
}
|