inertia-sails 0.3.1 → 0.3.3
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.
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
const isInertiaRequest = require('../helpers/is-inertia-request')
|
|
2
|
-
|
|
3
1
|
const resolveValidationErrors = require('../helpers/resolve-validation-errors')
|
|
4
2
|
function inertia(hook) {
|
|
5
3
|
return function inertiaMiddleware(req, res, next) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
success: req.flash('success')
|
|
11
|
-
}
|
|
12
|
-
hook.share('flash', flash)
|
|
13
|
-
|
|
14
|
-
const validationErrors = resolveValidationErrors(req)
|
|
15
|
-
req.flash('errors', validationErrors)
|
|
16
|
-
|
|
17
|
-
hook.share('errors', req.flash('errors')[0] || {})
|
|
4
|
+
const flash = {
|
|
5
|
+
message: req.flash('message'),
|
|
6
|
+
error: req.flash('error'),
|
|
7
|
+
success: req.flash('success')
|
|
18
8
|
}
|
|
19
9
|
|
|
10
|
+
hook.share('flash', flash)
|
|
11
|
+
|
|
12
|
+
const validationErrors = resolveValidationErrors(req)
|
|
13
|
+
req.flash('errors', validationErrors)
|
|
14
|
+
hook.share('errors', req.flash('errors')[0] || {})
|
|
20
15
|
return next()
|
|
21
16
|
}
|
|
22
17
|
}
|
package/lib/render.js
CHANGED
|
@@ -17,8 +17,11 @@ module.exports = async function render(req, res, data) {
|
|
|
17
17
|
|
|
18
18
|
const queryParams = req.query
|
|
19
19
|
if (req.method === 'GET' && Object.keys(queryParams).length) {
|
|
20
|
-
//
|
|
21
|
-
|
|
20
|
+
// Only append query params if the URL doesn't already contain them
|
|
21
|
+
// This prevents duplication when redirecting with query parameters
|
|
22
|
+
if (!page.url.includes('?')) {
|
|
23
|
+
page.url += `?${encode(queryParams)}`
|
|
24
|
+
}
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
if (req.get(inertiaHeaders.INERTIA)) {
|