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