2018-03-05 20:51:42 -08:00
|
|
|
import fetch from 'node-fetch'
|
2018-02-18 12:03:37 -08:00
|
|
|
|
2018-03-05 21:21:28 -08:00
|
|
|
export async function waitForMastodonUiToStart () {
|
2018-02-18 12:03:37 -08:00
|
|
|
while (true) {
|
|
|
|
try {
|
2018-02-18 17:28:08 -08:00
|
|
|
let html = await ((await fetch('http://127.0.0.1:3035/packs/common.js')).text())
|
2018-03-05 21:21:28 -08:00
|
|
|
if (html) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.log('Waiting for Mastodon UI to start up...')
|
2018-04-10 20:15:04 -07:00
|
|
|
await new Promise(resolve => setTimeout(resolve, 5000))
|
2018-03-05 21:21:28 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log('Mastodon UI started up')
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function waitForMastodonApiToStart () {
|
|
|
|
while (true) {
|
|
|
|
try {
|
|
|
|
let json = await ((await fetch('http://127.0.0.1:3000/api/v1/instance')).json())
|
|
|
|
if (json.uri) {
|
2018-02-18 12:03:37 -08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
} catch (err) {
|
2018-03-05 21:21:28 -08:00
|
|
|
console.log('Waiting for Mastodon API to start up...')
|
2018-04-10 20:15:04 -07:00
|
|
|
await new Promise(resolve => setTimeout(resolve, 5000))
|
2018-02-18 12:03:37 -08:00
|
|
|
}
|
|
|
|
}
|
2018-03-05 21:21:28 -08:00
|
|
|
console.log('Mastodon API started up')
|
2018-02-18 12:03:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (require.main === module) {
|
2018-03-06 09:21:17 -08:00
|
|
|
Promise.resolve()
|
|
|
|
.then(waitForMastodonApiToStart)
|
|
|
|
.then(waitForMastodonUiToStart).catch(err => {
|
2018-03-06 23:57:06 -08:00
|
|
|
console.error(err)
|
|
|
|
process.exit(1)
|
|
|
|
})
|
2018-02-18 15:30:42 -08:00
|
|
|
}
|