Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/hooks/webui/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logo, logger, store } from '../../utils'
import { join } from 'path'
import { screen, BrowserWindow, ipcMain, app } from 'electron'
import { screen, BrowserWindow, ipcMain, app, session } from 'electron'
import serve from 'electron-serve'

serve({ scheme: 'webui', directory: `${__dirname}/app` })
Expand All @@ -16,7 +16,8 @@ const createWindow = () => {
width: store.get('window.width', dimensions.width < 1440 ? dimensions.width : 1440),
height: store.get('window.height', dimensions.height < 900 ? dimensions.height : 900),
webPreferences: {
preload: join(__dirname, 'preload.js')
preload: join(__dirname, 'preload.js'),
webSecurity: false
}
})

Expand Down Expand Up @@ -56,6 +57,11 @@ export default async function (ctx) {
window.webContents.send('config.changed', store.store)
})

session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
delete details.requestHeaders['Origin']
callback({ cancel: false, requestHeaders: details.requestHeaders }) // eslint-disable-line
})

return new Promise(resolve => {
window.on('ready-to-show', () => {
logger.info('WebUI window ready')
Expand Down
27 changes: 0 additions & 27 deletions src/utils/daemon.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import IPFSFactory from 'ipfsd-ctl'
import logger from './logger'
import { showConnFailureErrorMessage } from './errors'
import { join } from 'path'
import fs from 'fs-extra'
import { spawnSync } from 'child_process'
import findExecutable from 'ipfsd-ctl/src/utils/find-ipfs-executable'

Expand All @@ -16,30 +14,6 @@ function repoFsck (path) {
})
}

async function configure (ipfsd) {
const cfgFile = join(ipfsd.repoPath, 'config')
const cfg = await fs.readJSON(cfgFile)

let origins = []
try {
origins = cfg.API.HTTPHeaders['Access-Control-Allow-Origin']
} catch (e) {
logger.warn(e)
}

if (!Array.isArray(origins)) {
origins = []
}

if (!origins.includes('webui://-')) origins.push('webui://-')
if (!origins.includes('https://webui.ipfs.io')) origins.push('https://webui.ipfs.io')

cfg.API.HTTPHeaders['Access-Control-Allow-Origin'] = origins
cfg.API.HTTPHeaders['Access-Control-Allow-Methods'] = ['PUT', 'GET', 'POST']

await fs.writeJSON(cfgFile, cfg)
}

async function spawn ({ type, path, keysize }) {
const factory = IPFSFactory.create({ type: type })

Expand Down Expand Up @@ -79,7 +53,6 @@ async function start (ipfsd, { flags }) {

export default async function (opts) {
const ipfsd = await spawn(opts)
await configure(ipfsd)

if (!ipfsd.started) {
await start(ipfsd, opts)
Expand Down