inertia-sails 0.3.0 → 0.3.1
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/lib/location.js +6 -8
- package/package.json +1 -1
package/lib/location.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
const { INERTIA, LOCATION } = require('./helpers/inertia-headers')
|
|
2
2
|
|
|
3
3
|
module.exports = function (req, res, url) {
|
|
4
|
-
// If this is an Inertia request, send a 409 Conflict response
|
|
5
|
-
// with the X-Inertia-Location header so the client performs a full window.location visit.
|
|
6
4
|
if (req.get(INERTIA)) {
|
|
5
|
+
// If the method is PUT, PATCH, or DELETE, force a 303 redirect (so the next request is a GET)
|
|
6
|
+
if (['PUT', 'PATCH', 'DELETE'].includes(req.method)) {
|
|
7
|
+
return res.redirect(303, url)
|
|
8
|
+
}
|
|
9
|
+
// If this is an Inertia request, send a 409 Conflict response
|
|
10
|
+
// with the X-Inertia-Location header so the client performs a full window.location visit.
|
|
7
11
|
res.set(LOCATION, url)
|
|
8
12
|
return res.status(409).end()
|
|
9
13
|
}
|
|
10
14
|
|
|
11
|
-
// For non-Inertia requests:
|
|
12
|
-
// If the method is PUT, PATCH, or DELETE, force a 303 redirect (so the next request is a GET)
|
|
13
|
-
if (['PUT', 'PATCH', 'DELETE'].includes(req.method)) {
|
|
14
|
-
return res.redirect(303, url)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
15
|
// Otherwise, perform a standard redirect (default is typically a 302)
|
|
18
16
|
return res.redirect(url)
|
|
19
17
|
}
|