Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use referer for redirect #229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions controllers/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ function process (staticman, req, res) {
const fields = req.query.fields || req.body.fields
const options = req.query.options || req.body.options || {}

options.referer = req.headers.referer

return staticman.processEntry(fields, options).then(data => {
sendResponse(res, {
redirect: data.redirect,
Expand Down
4 changes: 3 additions & 1 deletion lib/Staticman.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,11 @@ Staticman.prototype.processEntry = function (fields, options) {
commitMessage
)
}).then(result => {
let referer = this.siteConfig.get("referer")
let redirect = (referer.enabled && options.referer)? options.referer+referer.postfix : options.redirect || false
return {
fields: fields,
redirect: options.redirect ? options.redirect : false
redirect: redirect
}
}).catch(err => {
return Promise.reject(errorHandler('ERROR_PROCESSING_ENTRY', {
Expand Down
12 changes: 12 additions & 0 deletions siteConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ const schema = {
format: 'EncryptedString',
default: ''
}
},
referer: {
enabled: {
doc: 'Set to `true` to enable redirect back to referer page',
format: Boolean,
default: false
},
postfix: {
doc: 'Append this string to the referer to build the redirect adress',
format: String,
default: ''
}
}
}

Expand Down