Skip to content

Commit

Permalink
fix: support for IPFS_PATH/api (remote daemon)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
  • Loading branch information
hacdias committed Apr 17, 2020
1 parent 7f0c3b1 commit 9d1de70
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/daemon/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ function configExists (ipfsd) {
return fs.pathExistsSync(join(ipfsd.path, 'config'))
}

function apiFileExists (ipfsd) {
return fs.pathExistsSync(join(ipfsd.path, 'api'))
}

function configPath (ipfsd) {
return join(ipfsd.path, 'config')
}
Expand Down Expand Up @@ -265,6 +269,7 @@ async function checkPorts (ipfsd) {
module.exports = Object.freeze({
configPath,
configExists,
apiFileExists,
applyDefaults,
checkCorsConfig,
checkPorts
Expand Down
16 changes: 11 additions & 5 deletions src/daemon/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const i18n = require('i18next')
const { execFileSync } = require('child_process')
const { showDialog } = require('../dialogs')
const logger = require('../common/logger')
const { applyDefaults, checkCorsConfig, checkPorts, configExists } = require('./config')
const { applyDefaults, checkCorsConfig, checkPorts, configExists, apiFileExists } = require('./config')

function cannotConnectDialog (addr) {
showDialog({
Expand Down Expand Up @@ -63,20 +63,26 @@ async function spawn ({ flags, path, keysize }) {
// NOTE: https://github.com/ipfs/js-ipfsd-ctl/issues/500
if (configExists(ipfsd)) {
checkCorsConfig(ipfsd)
return ipfsd
return { ipfsd, isRemote: false }
}

// If config does not exist, but $IPFS_PATH/api exists, then
// it is a remote repository.
if (apiFileExists(ipfsd)) {
return { ipfsd, isRemote: true }
}

await ipfsd.init({
bits: keysize
})

applyDefaults(ipfsd)
return ipfsd
return { ipfsd, isRemote: false }
}

module.exports = async function (opts) {
const ipfsd = await spawn(opts)
await checkPorts(ipfsd)
const { ipfsd, isRemote } = await spawn(opts)
if (!isRemote) await checkPorts(ipfsd)

try {
await ipfsd.start()
Expand Down
10 changes: 4 additions & 6 deletions test/e2e/launch.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,23 @@ describe('Application launch', function () {
expect(config.API.HTTPHeaders['Access-Control-Allow-Origin']).to.deep.equal(specificOrigins)
})

/* TODO: support for IPFS_PATH/api is broken ATM (was removed at some point?)
it('starts with repository with "IPFS_PATH/api" file and no daemon running', async function () {
// create "remote" repo
const { ipfsd, configPath: remoteConfigPath } = await makeRepository({ start: true })
const remoteConfig = fs.readJsonSync(remoteConfigPath)
const { ipfsd } = await makeRepository({ start: true })

// create "local" repo
const { repoPath, configPath } = await makeRepository({ start: false })
fs.unlinkSync(configPath) // remove config file to ensure local repo can't be used

// create IPFS_PATH/api file to point at remote node
const apiPath = path.join(repoPath, 'api')
fs.writeFile(apiPath, remoteConfig.Addresses.API)
fs.writeFile(apiPath, ipfsd.apiAddr.toString())

const { app } = await startApp({ repoPath })
expect(app.isRunning()).to.be.true()
await daemonReady(app)
await ipfsd.stop()
}) */
})

it('starts with multiple api addresses', async function () {
const { repoPath, configPath } = await makeRepository({ start: false })
Expand Down

0 comments on commit 9d1de70

Please sign in to comment.