inertia-sails 0.1.8 → 0.1.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertia-sails",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "The Sails adapter for Inertia.",
5
5
  "main": "index.js",
6
6
  "sails": {
@@ -14,7 +14,7 @@
14
14
  "repository": {
15
15
  "type": "git",
16
16
  "url": "git+https://github.com/sailscastshq/boring-stack.git",
17
- "directory": "packages/inertia-sails"
17
+ "directory": "inertia-sails"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "sails": ">=1",
@@ -11,27 +11,29 @@ const getPartialData = require('./get-partial-data')
11
11
  const resolveValidationErrors = require('./resolve-validation-errors')
12
12
  function inertia(sails, { hook, sharedProps, sharedViewData, rootView }) {
13
13
  return function inertiaMiddleware(req, res, next) {
14
- /**
15
- * Flash messages stored in the session.
16
- * @typedef {Object} FlashMessages
17
- * @property {Array} message - Flash message(s).
18
- * @property {Array} error - Error message(s).
19
- * @property {Array} success - Success message(s).
20
- */
21
- const flash = {
22
- message: req.flash('message'),
23
- error: req.flash('error'),
24
- success: req.flash('success')
25
- }
26
- hook.share('flash', flash) // Share the flash object as props
27
- /**
28
- * Validation errors stored in the session, resolved and formatted for Inertia.js.
29
- * @type {Object}
30
- */
31
- const validationErrors = resolveValidationErrors(req)
32
- req.flash('errors', validationErrors) // Flash the validation error so we can share it later
14
+ if (isInertiaRequest(req)) {
15
+ /**
16
+ * Flash messages stored in the session.
17
+ * @typedef {Object} FlashMessages
18
+ * @property {Array} message - Flash message(s).
19
+ * @property {Array} error - Error message(s).
20
+ * @property {Array} success - Success message(s).
21
+ */
22
+ const flash = {
23
+ message: req.flash('message'),
24
+ error: req.flash('error'),
25
+ success: req.flash('success')
26
+ }
27
+ hook.share('flash', flash) // Share the flash object as props
28
+ /**
29
+ * Validation errors stored in the session, resolved and formatted for Inertia.js.
30
+ * @type {Object}
31
+ */
32
+ const validationErrors = resolveValidationErrors(req)
33
+ req.flash('errors', validationErrors) // Flash the validation error so we can share it later
33
34
 
34
- hook.share('errors', req.flash('errors')[0] || {}) // Share validation errors as props
35
+ hook.share('errors', req.flash('errors')[0] || {}) // Share validation errors as props
36
+ }
35
37
 
36
38
  hook.render = function (component, props = {}, viewData = {}) {
37
39
  const allProps = {
Binary file