sailscastshq / boring-stack

Ship JavaScript products with battle-tested technologies in days not weeks.
https://docs.sailscasts.com/boring-stack/getting-started
MIT License
390 stars 19 forks source link

Use custom responses and exits #86

Closed DominusKelvin closed 6 months ago

DominusKelvin commented 6 months ago

Description

For the longest time sails.inertia.render felt like a hack but it was the only way I thought possible at the time to get the req and res needed to implement the Inertia protocol.

Ideally I'd like for the Inertia implementation in Sails to embrace actions2 exits. This was the syntax I've dreamt about for a while

module.exports = {
  friendlyName: 'Home',

  description: 'Home index.',

  inputs: {},

  exits: {
    success: {
      responseType: 'inertia'
    }
  },

  fn: async function () {
    return { page: 'index' }
  }
}

It confirms to how Sails return or throw responses.

This implementation will solve #78 as well because the race condition will no longer exists as sails.inertia.render won't be implemented at all in the InertiaMiddleware

Deprecate sails.inertia.location and sails.inertia.render

These two methods will be deprecated in favour of using custom responses

The middleware will now be lightweight as it sets the shared props and flash messages.

Upgrading

For now you'd have to just copy the inertia and inertiaRedirect responses in api/responses/ of the mellow-vue template into your applications api/responses. In the future I think I'll provide a Sails generator that will expose sails generate response inertia and sails generate response inertiaRedirect so we can evolve these responses and you run a single command to get the updates if need be.

Let me know your thoughts on this.