Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
inertia-sails
Advanced tools
The quickest way to get setup an Inertia powered Sails app is to use the create-sails scaffolding tool. Just run
npx create-sails <project-name>
Do replace
<project-name>
with the name you want your project to be.
If you are using the create-sails scaffolding tool then the Frontend framework you choose from the CLI prompt should already be setup for you.
Sending back an Inertia responses is pretty simple, just use the sails.inertia.render
method in your Sails actions(You can look at the example actions if you used create-sails). The render
method accepts two arguments, the first is the name of the component you want to render from within your pages
directory in assets/js
(without the file extension).
The second argument is the props object where you can provide props to your components.
If you have data that you want to be provided as a prop to every component (a common use-case is informationa about the authenticated user) you can use the sails.inertia.share
method.
In Sails having a custom hook by running sails generate hook custom
will scaffolding a project level hook in which you can share the loggedIn user information for example. Below is a real world use case:
/**
* custom hook
*
* @description :: A hook definition. Extends Sails by adding shadow routes, implicit actions, and/or initialization logic.
* @docs :: https://sailsjs.com/docs/concepts/extending-sails/hooks
*/
module.exports = function defineCustomHook(sails) {
return {
/**
* Runs when this Sails app loads/lifts.
*/
initialize: async function () {
sails.log.info('Initializing custom hook (`custom`)')
},
routes: {
before: {
'GET /': {
skipAssets: true,
fn: async function (req, res, next) {
if (req.session.userId) {
const loggedInUser = await User.findOne({
id: req.session.userId
})
if (!loggedInUser) {
sails.log.warn(
'Somehow, the user record for the logged-in user (`' +
req.session.userId +
'`) has gone missing....'
)
delete req.session.userId
return res.redirect('/signin')
}
sails.inertia.share('loggedInUser', loggedInUser)
return next()
}
return next()
}
}
}
}
}
}
If you used the create-sails
scaffolding tool, you will find the configuration file for Inertia.js in config/inertia.js
. You will mostly use this file for asset-versioning in Inertia by setting either a number or string that you can update when your assets changes. Below is an example of how this file looks like:
/**
* Inertia configuration
* (sails.config.inertia)
*
* Use the settings below to configure session integration in your app.
*
* For more information on Inertia configuration, visit:
* https://inertia-sails.sailscasts.com
*/
module.exports.inertia = {
/**
* https://inertiajs.com/asset-versioning
* You can pass a string, number that changes when your assets change
* or a function that returns the said string, number.
* e.g 4 or () => 4
*/
// version: 1,
}
Visit inertiajs.com to learn more.
FAQs
The Sails adapter for Inertia.
The npm package inertia-sails receives a total of 0 weekly downloads. As such, inertia-sails popularity was classified as not popular.
We found that inertia-sails demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.