pinokiod 7.1.67 → 7.1.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "7.1.67",
3
+ "version": "7.1.68",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -5480,43 +5480,53 @@ class Server {
5480
5480
  return list
5481
5481
  }
5482
5482
  async check_router_up() {
5483
- // check if caddy is runnign properly
5484
- // try https://pinokio.localhost
5485
- // if it works, proceed
5486
- // if not, redirect
5487
- let https_running = false
5483
+ let response
5484
+ let config
5488
5485
  try {
5489
5486
  let res = await axios.get(`http://127.0.0.1:2019/config/`, {
5490
5487
  timeout: 2000
5491
5488
  })
5492
- let test = /pinokio\.localhost/.test(JSON.stringify(res.data))
5493
- if (test) {
5494
- https_running = true
5495
- }
5489
+ config = res.data
5496
5490
  } catch (e) {
5497
- // console.log(e)
5498
- }
5499
- // console.log({ https_running })
5500
- if (!https_running) {
5501
- return { error: "pinokio.host not yet available" }
5491
+ response = {
5492
+ stage: "caddy_admin_unavailable",
5493
+ error: "caddy admin unavailable",
5494
+ detail: e && e.message ? e.message : String(e)
5495
+ }
5502
5496
  }
5503
-
5504
-
5505
- // check if pinokio.localhost router is running
5506
- let router_running = false
5507
- let router = this.kernel.router.published()
5508
- for(let ip in router) {
5509
- let domains = router[ip]
5510
- if (domains.includes("pinokio.localhost")) {
5511
- router_running = true
5512
- break
5497
+ if (!response) {
5498
+ if (config === null || typeof config === "undefined") {
5499
+ response = {
5500
+ stage: "caddy_config_empty",
5501
+ error: "caddy config not yet loaded"
5502
+ }
5503
+ } else if (!/pinokio\.localhost/.test(JSON.stringify(config))) {
5504
+ response = {
5505
+ stage: "caddy_route_missing",
5506
+ error: "pinokio.localhost missing from caddy config"
5507
+ }
5508
+ } else {
5509
+ let router_running = false
5510
+ let router = this.kernel.router.published()
5511
+ for (let ip in router) {
5512
+ let domains = router[ip]
5513
+ if (domains.includes("pinokio.localhost")) {
5514
+ router_running = true
5515
+ break
5516
+ }
5517
+ }
5518
+ if (!router_running) {
5519
+ response = {
5520
+ stage: "pinokio_router_missing",
5521
+ error: "pinokio.localhost not yet published by Pinokio router"
5522
+ }
5523
+ }
5513
5524
  }
5514
5525
  }
5515
- if (!router_running) {
5516
- return { error: "pinokio.localhost not yet available" }
5526
+ if (!response) {
5527
+ response = { success: true, stage: "ready" }
5517
5528
  }
5518
-
5519
- return { success: true }
5529
+ return response
5520
5530
  }
5521
5531
  async start(options) {
5522
5532
  this.debug = false
@@ -11428,37 +11438,8 @@ class Server {
11428
11438
  return
11429
11439
  }
11430
11440
 
11431
- let https_running = false
11432
- try {
11433
- let res = await axios.get(`http://127.0.0.1:2019/config/`, {
11434
- timeout: 2000
11435
- })
11436
- let test = /pinokio\.localhost/.test(JSON.stringify(res.data))
11437
- if (test) {
11438
- https_running = true
11439
- }
11440
- } catch (e) {
11441
- console.log(e)
11442
- }
11443
- if (!https_running) {
11444
- // res.json({ error: "pinokio.host not yet available" })
11445
- res.redirect("/setup/connect?callback=/connect/" + req.params.provider)
11446
- return
11447
- }
11448
-
11449
-
11450
- // check if pinokio.localhost router is running
11451
- let router_running = false
11452
- let router = this.kernel.router.published()
11453
- for(let ip in router) {
11454
- let domains = router[ip]
11455
- if (domains.includes("pinokio.localhost")) {
11456
- router_running = true
11457
- break
11458
- }
11459
- }
11460
- if (!router_running) {
11461
- // res.json({ error: "pinokio.localhost not yet available" })
11441
+ const routerStatus = await this.check_router_up()
11442
+ if (!routerStatus.success) {
11462
11443
  res.redirect("/setup/connect?callback=/connect/" + req.params.provider)
11463
11444
  return
11464
11445
  }
@@ -15576,6 +15557,13 @@ class Server {
15576
15557
  server_ready: true,
15577
15558
  phase: this.getStartupStatus().phase === "idle" ? "ready" : this.getStartupStatus().phase
15578
15559
  })
15560
+ if (this.kernel && this.kernel.peer && this.kernel.peer.https_active) {
15561
+ this.kernel.refresh(true).then(() => {
15562
+ return this.check_router_up()
15563
+ }).catch((error) => {
15564
+ console.warn("[Pinokiod] initial secure router refresh failed", error && error.message ? error.message : error)
15565
+ })
15566
+ }
15579
15567
  resolve()
15580
15568
  });
15581
15569
  this.httpTerminator = createHttpTerminator({
@@ -243,6 +243,12 @@ document.addEventListener("DOMContentLoaded", async () => {
243
243
  const waitRoot = document.querySelector(".requirements .content")
244
244
  const waitLabel = document.querySelector(".requirements .content .loading span")
245
245
  const WAIT_TIMEOUT_MS = 120000
246
+ const ROUTER_STAGE_MESSAGES = {
247
+ caddy_admin_unavailable: "Restarting Pinokio... (waiting for Caddy)",
248
+ caddy_config_empty: "Restarting Pinokio... (publishing secure router)",
249
+ caddy_route_missing: "Restarting Pinokio... (loading pinokio.localhost)",
250
+ pinokio_router_missing: "Restarting Pinokio... (waiting for Pinokio router)"
251
+ }
246
252
  const setWaitLabel = (message) => {
247
253
  if (waitLabel) {
248
254
  waitLabel.textContent = message
@@ -314,10 +320,13 @@ document.addEventListener("DOMContentLoaded", async () => {
314
320
  lastKnownError = startupStatus.error
315
321
  }
316
322
  if (startupStatus && startupStatus.phase) {
317
- lastKnownPhase = startupStatus.phase
318
- const phaseMessage = startupStatus.phase === "ready"
323
+ lastKnownPhase = (routerStatus && routerStatus.stage) || startupStatus.phase
324
+ const routerStageMessage = routerStatus && routerStatus.stage
325
+ ? ROUTER_STAGE_MESSAGES[routerStatus.stage]
326
+ : null
327
+ const phaseMessage = routerStageMessage || (startupStatus.phase === "ready"
319
328
  ? "Secure router is almost ready..."
320
- : `Restarting Pinokio... (${startupStatus.phase.replace(/_/g, " ")})`
329
+ : `Restarting Pinokio... (${startupStatus.phase.replace(/_/g, " ")})`)
321
330
  setWaitLabel(phaseMessage)
322
331
  }
323
332