Skip to content

Commit

Permalink
Merge pull request #237 from datopian/bug/page-load-fail-if-wordpress…
Browse files Browse the repository at this point in the history
…-no-response

Fix:Add timeout to the wordpress query if there is no response
  • Loading branch information
anuveyatsu authored Jun 12, 2022
2 parents 88cb093 + 740818b commit f16a8b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions env.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ API_URL=http://127.0.0.1:5000/api/3/action/
WP_URL=http://127.0.0.1:6000
WP_BLOG_PATH=
WP_TOKEN=
WP_TIMEOUT=

# Change that in production!
SESSION_SECRET="keyboard cat"
Expand Down
11 changes: 9 additions & 2 deletions plugins/wp/cms.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const config = require('../../config')

const wpcom = require('wpcom')(config.get('WP_TOKEN'))

const timeout = config.get('WP_TIMEOUT', 60000)

class CmsModel {
constructor() {
Expand Down Expand Up @@ -40,14 +40,21 @@ class CmsModel {
if (id) {
query.id = id
}
query.slug = slug
query.slug = slug;
let queryCompleted = false
this.blog.post(query).get((err, data) => {
queryCompleted = true
if (err) {
reject(err)
} else {
resolve(data)
}
})
setTimeout(() => {
if (!queryCompleted) {
reject(new Error('Timeout'))
}
}, timeout)
}
})
}
Expand Down

0 comments on commit f16a8b1

Please sign in to comment.