Skip to content

Commit

Permalink
fix: 🐛 adjust reload port based on elder.js origin
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Reese committed Oct 22, 2020
1 parent f1480bc commit 5ac53fd
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 5,772 deletions.
12 changes: 8 additions & 4 deletions packages/browser-reload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const plugin = {
const notProd = process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'PRODUCTION';

plugin.run = !plugin.settings.build && notProd;
plugin.origin = plugin.settings.origin.includes('://') ? plugin.settings.origin : 'http://localhost';

plugin.serverPort = process.env.SERVER_PORT || 3000;

if (plugin.run) {
plugin.ws = require('http').createServer();
plugin.io = require('socket.io')(plugin.ws);
Expand All @@ -22,9 +26,9 @@ const plugin = {
},
config: {
port: 8080,
delay: 200,
delay: 600,
preventReloadQS: 'noreload',
retryCount: 50,
retryCount: 300,
},
hooks: [
{
Expand All @@ -47,7 +51,7 @@ const plugin = {
}
async function checkServer(tryCount = 0){
var up = await fetch('http://localhost:3000');
var up = await fetch('${plugin.origin}:${plugin.serverPort}');
if(up.ok) return true;
if(tryCount > ${plugin.config.retryCount}){
return false;
Expand All @@ -61,7 +65,7 @@ const plugin = {
socketio.onload = function() {
if(document.location.search.indexOf('${plugin.config.preventReloadQS}') === -1){
var disconnected = false;
var socket = io('http://localhost:${plugin.config.port}');
var socket = io('${plugin.origin}:${plugin.config.port}');
socket.on('connect', async function() {
if (disconnected) {
console.log('reloading');
Expand Down
314 changes: 0 additions & 314 deletions packages/browser-reload/package-lock.json

This file was deleted.

Loading

0 comments on commit 5ac53fd

Please sign in to comment.