dsh-unlag 1.9.47 → 1.9.49

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.
Files changed (2) hide show
  1. package/index.js +17 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1672,9 +1672,13 @@ function serveButton(ctx, controller, config) {
1672
1672
  const handlers = [
1673
1673
  [
1674
1674
  `${BASE_PATH}/state`,
1675
- (_req, res) => {
1675
+ (req, res) => {
1676
1676
  // A disposed context answers with a status instead of a throw the server has to guess at.
1677
1677
  try {
1678
+ // These two are reads. Any other method is told so, the way the app's own bundle route
1679
+ // answers a method it does not serve.
1680
+ const method = String(req?.method ?? 'GET').toUpperCase()
1681
+ if (method !== 'GET' && method !== 'HEAD') return sendJson(res, 405, { status: 'method' })
1678
1682
  sendJson(res, 200, { version: VERSION, code: CODE_STAMP, plugins: settings.reloadPlugins, page: settings.reloadInterface, shim: bundleShimStatus(ctx) })
1679
1683
  } catch (error) {
1680
1684
  log(`cannot describe this copy of the plugin: ${error?.message ?? error}`)
@@ -1684,10 +1688,12 @@ function serveButton(ctx, controller, config) {
1684
1688
  ],
1685
1689
  [
1686
1690
  `${BASE_PATH}/graph`,
1687
- (_req, res) => {
1691
+ (req, res) => {
1688
1692
  // The page reads this before a rebuild; an answer that throws would leave the press with
1689
1693
  // no verdict at all, so the whole body is bounded and answers either way.
1690
1694
  try {
1695
+ const method = String(req?.method ?? 'GET').toUpperCase()
1696
+ if (method !== 'GET' && method !== 'HEAD') return sendJson(res, 405, { status: 'method' })
1691
1697
  ensureBundleShim(ctx)
1692
1698
  sendJson(res, 200, { graph: liveBootGraph(ctx) })
1693
1699
  } catch (error) {
@@ -1785,8 +1791,14 @@ function serveButton(ctx, controller, config) {
1785
1791
  if (!settings.reloadPlugins) return sendJson(res, 200, { status: 'off' })
1786
1792
  const limit = Number(process.env.DSH_UNLAG_ANSWER_MS ?? '') || RELOAD_ANSWER_MS
1787
1793
  let timer = null
1794
+ let timedOut = false
1788
1795
  const stillApplying = new Promise((resolve) => {
1789
- timer = setTimeout(() => resolve({ status: 'applying', warnings: [], pending: [], restartReason: null, failedEntries: [] }), limit)
1796
+ timer = setTimeout(() => {
1797
+ // Only the timer's own answer means the update outlasted the page: an update that
1798
+ // says "applying" itself is a press that arrived during another one, not a slow one.
1799
+ timedOut = true
1800
+ resolve({ status: 'applying', warnings: [], pending: [], restartReason: null, failedEntries: [] })
1801
+ }, limit)
1790
1802
  })
1791
1803
  let answeredEarly = false
1792
1804
  try {
@@ -1807,7 +1819,8 @@ function serveButton(ctx, controller, config) {
1807
1819
  const outcome = await Promise.race([work, stillApplying])
1808
1820
  if (outcome?.status === 'applying') {
1809
1821
  answeredEarly = true
1810
- log('the update outlasted the answer the page waits for: the press is told it is still applying')
1822
+ if (timedOut) log('the update outlasted the answer the page waits for: the press is told it is still applying')
1823
+ else log('a press arrived while an update is already applying: the press is told it is still applying')
1811
1824
  }
1812
1825
  sendJson(res, 200, outcome)
1813
1826
  } finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-unlag",
3
- "version": "1.9.47",
3
+ "version": "1.9.49",
4
4
  "type": "module",
5
5
  "description": "A press applies plugin edits right away and brings a laggy interface back; automatic reloading stays off unless you turn it on, so the press is the only trigger, and nothing restarts.",
6
6
  "license": "MIT",