Browse Source

Update URLs to "external" so developer can share with multiple devices.

pull/1/head
Roman Axelrod 3 years ago
parent
commit
9ac3a19b2f
  1. 4
      layouts/index.hbs
  2. 14
      server.js

4
layouts/index.hbs

@ -13,10 +13,10 @@
<script> <script>
window.devTool = { window.devTool = {
previewFrameUrl: 'http://localhost:{{ port }}/view/{{ baseView }}', previewFrameUrl: '{{ previewFrameUrl }}',
}; };
</script> </script>
<iframe id="preview_frame" src="http://localhost:{{ port }}/view/{{ baseView }}" class="breakpoint"></iframe> <iframe id="preview_frame" src="{{ previewFrameUrl }}" class="breakpoint"></iframe>
<script src="/scripts/dist/index.min.js"></script> <script src="/scripts/dist/index.min.js"></script>
</body> </body>

14
server.js

@ -40,6 +40,7 @@ buildScriptFiles()
let port = 3000; let port = 3000;
let externalUrl = ''; let externalUrl = '';
let previewFrameUrl = `http://localhost:${port}`;
const app = express(); const app = express();
const hbs = create({ const hbs = create({
@ -71,13 +72,14 @@ app.get('/', async (req, res) => {
} }
const baseView = config.has('baseView') ? config.get('baseView') : 'container'; const baseView = config.has('baseView') ? config.get('baseView') : 'container';
const baseViewUrl = `view/${baseView}`;
data.helpers = { data.helpers = {
port, port,
include_partial: (path) => projectDir + path, include_partial: (path) => projectDir + path,
baseView: baseView, baseView,
externalUrl: `${externalUrl}/view/${baseView}`, externalUrl: `${externalUrl}/${baseViewUrl}`,
previewFrameUrl: `http://localhost:${port}/view/${baseView}`, previewFrameUrl: `${previewFrameUrl}/${baseViewUrl}`,
} }
res.render('index', data); res.render('index', data);
@ -210,8 +212,10 @@ const listener = app.listen(0, async () => {
proxy: `http://localhost:${PORT}`, proxy: `http://localhost:${PORT}`,
open: false open: false
}, (err, bs) => { }, (err, bs) => {
externalUrl = bs.getOptionIn(["urls"]).get('external'); const options = bs.getOptions().toJS();
port = bs.server._connectionKey.split(':').pop(); previewFrameUrl = options.urls.external;
externalUrl = previewFrameUrl.replace(options.port, options.proxy.url.port);
port = options.port;
}); });
}); });

Loading…
Cancel
Save