pinafore/bin/wait-for-mastodon-to-start.js
2018-03-05 20:51:42 -08:00

25 lines
647 B
JavaScript

import fetch from 'node-fetch'
export async function waitForMastodonToStart () {
while (true) {
try {
let json = await ((await fetch('http://127.0.0.1:3000/api/v1/instance')).json())
let html = await ((await fetch('http://127.0.0.1:3035/packs/common.js')).text())
if (json.uri && html) {
break
}
} catch (err) {
console.log('Waiting for Mastodon to start up...')
await new Promise(resolve => setTimeout(resolve, 1000))
}
}
console.log('Mastodon started up')
}
if (require.main === module) {
waitForMastodonToStart().catch(err => {
console.error(err)
process.exit(1)
})
}