
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
nuxt-server-init
Advanced tools
Pre-run scripts to validate, get or insert config variables to Nuxt 3
A Nuxt 3 module to run scripts before Nuxt 3 is ready to serve.
Add nuxt-server-init dependency to your project
npm install nuxt-server-init
Add nuxt-server-init to the modules section of nuxt.config.js
{
modules: [
'nuxt-server-init'
]
}
Create a file called server.init.ts
(or .js
) in the root directory of your Nuxt 3 project.
This file needs to export a const that returns an object that contains a pass
boolean.
export default const = { pass: true }
By default, an error will be thrown (Nuxt 3 will be halted) if pass
is returned as false
.
If you want Nuxt 3 to continue launching, also return continueOnFail: true
. (You will still get failure logs in the console)
export default const = { pass: false, continueOnFail:true }
Depending on your use case, you may want to use an inline function to simplify your code or return the values from multiple functions.
export const result = (() => {
// do something cool
return { pass: true, continueOnFail:true }
})()
If you need to do some long running tasks, simply set the const's function to async
and add your await
s within the code block
export const result = (async () => {
// sleep for 5 seconds - simulate a long running check
await new Promise(resolve => setTimeout(resolve, 5000))
return { pass: true, continueOnFail:true }
})()
To insert new config variables into Nuxt, return runtimeConfig
, publicConfig
, and/or appConfig
as an object
with key: "value"
pairs
export const result = (() => {
// setting the runtimeConfig values to be returned
const runtimeConfig = {
foo: 'bar'
} // will add the variables for server side config only
const publicConfig = {
gee: 'wiz'
} // will add the variables to server and client config
const appConfig = {
hello: 'world',
pizza: 'Best Food!'
} // will add the variables to the app config
return { pass: true, runtimeConfig, publicConfig, appConfig }
})()
To load types, import ServerInitResult from the module
import { ServerInitResult } from 'nust-server-init'
export const result: Promise<ServerInitResult> = (async () => {
// return the results
return { pass: true, continueOnFail, runtimeConfig, publicConfig, appConfig }// will be correctly typed
})()
To run multiple scripts, add the file names to the module options in nuxt.config.ts
.
File names can include or exclude the extension, and will be run in the order they are written.
modules: ['../src/module'],
serverInit: {
scripts: ['example.init', 'another.init.ts']
}
When adding script file names to nuxt.config.ts
, the default server.init.ts
will not be run unless it is specifically added.
Adding .init
is not required, but helps ensure everyone understands what the file is for.
To keep your console logs clean, you may want to set the module to silent. You will still get log messages on failure and any console.log
statements within your scripts.
To do this, add silent: true
to the module's options in your nuxt.config.ts
file
modules: ['../src/module'],
serverInit: {
silent: true
}
Contributions are always welcome! Please open an issue and/or a pull request
To run locally:
FAQs
Pre-run scripts to validate, get or insert config variables to Nuxt 3
The npm package nuxt-server-init receives a total of 0 weekly downloads. As such, nuxt-server-init popularity was classified as not popular.
We found that nuxt-server-init demonstrated a not healthy version release cadence and project activity because the last version was released 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
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.