Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Revert "refactor: serve content over http server"
Browse files Browse the repository at this point in the history
This reverts commit 5418e3a.
  • Loading branch information
mrfelton committed Nov 15, 2019
1 parent 708e1f5 commit d151b6b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .testcafe-electron-rc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"mainWindowUrl": "http://localhost:3100/index.html",
"mainWindowUrl": "./dist/index.html",
"appPath": "."
}
36 changes: 9 additions & 27 deletions electron/controller.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { app, ipcMain } from 'electron'
import serveStatic from 'serve-static'
import http from 'http'
import finalhandler from 'finalhandler'
import getPort from 'get-port'
import { mainLog } from '@zap/utils/log'
import sanitize from '@zap/utils/sanitize'

Expand Down Expand Up @@ -42,7 +38,15 @@ class ZapController {
*
* @param {[object]} options Options to pass through to the renderer
*/
async init(options = {}) {
init(options) {
// Load the application into the main window.
if (process.env.HOT) {
const port = process.env.PORT || 1212
this.mainWindow.loadURL(`http://localhost:${port}/dist/index.html`)
} else {
this.mainWindow.loadURL(`file://${__dirname}/index.html`)
}

// Once the winow content has fully loaded, bootstrap the app.
this.mainWindow.webContents.on('did-finish-load', () => {
mainLog.trace('webContents.did-finish-load')
Expand All @@ -54,28 +58,6 @@ class ZapController {
// Start app.
this.initApp(options)
})

// Load the application into the main window.
if (process.env.HOT) {
// If hot mode is enabled, serve from webpack
const port = process.env.PORT || 1212
this.mainWindow.loadURL(`http://localhost:${port}/dist/index.html`)
}
// Otherwise it's a production build, serve content over a static html server.
// We do this rather than loading over a `file://` in order to mitigate issues with external services wrongly
// detecting that we don't support ssl.
else {
const serve = serveStatic(__dirname, { index: ['index.html'] })
const server = http.createServer((req, res) => {
serve(req, res, finalhandler(req, res))
})
const port = await getPort({
host: 'localhost',
port: getPort.makeRange(3100, 3199),
})
server.listen(port)
this.mainWindow.loadURL(`http://localhost:${port}/index.html`)
}
}

/**
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@
"downshift": "3.4.1",
"dropbox": "4.0.30",
"electron-is-dev": "1.1.0",
"finalhandler": "1.1.2",
"focus-visible": "5.0.2",
"get-port": "5.0.0",
"googleapis": "44.0.0",
Expand Down Expand Up @@ -369,7 +368,6 @@
"reselect": "4.0.0",
"satoshi-bitcoin": "1.0.4",
"semver": "6.3.0",
"serve-static": "1.14.1",
"source-map-support": "0.5.16",
"split2": "3.1.1",
"styled-components": "4.4.1",
Expand Down
2 changes: 0 additions & 2 deletions webpack/webpack.config.dll.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ export default merge.smart(baseConfig, {
'config',
'electron',
'electron-is-dev',
'finalhandler',
'get-port',
'lndconnect',
'lnd-grpc',
'react-hot-loader',
'redux-electron-ipc',
'rimraf',
'serve-static',
'source-map-support',
'googleapis',
'keytar',
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9153,7 +9153,7 @@ fill-range@^7.0.1:
dependencies:
to-regex-range "^5.0.1"

finalhandler@1.1.2, finalhandler@~1.1.2:
finalhandler@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.1.2.tgz#b7e7d000ffd11938d0fdb053506f6ebabe9f587d"
integrity sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==
Expand Down

0 comments on commit d151b6b

Please sign in to comment.