Comments (10)
Probably easier to build a wrapper for defineEventHandler
and similar that covers that
from nuxt.
Allowing to disable certain features from Nuxt/Nitro layers (server routes, pages, components) is something we might think about to support in Nuxt ππΌ (we might introduce a new $layer
configuration API to allow disabling certain routes)
Generally, I would highly advice to prefer the composable/util methods over global patterns such as plugins and middleware (also not wrappers You might want to use object syntax for fine control instead). especially for Nuxt layers when a layer can have undesired global side effects.
@samydoesit I got your immediate question but I think we might think of some faster solutions. Do you mind to update your sandbox/repro with the current multi-app of your project?
from nuxt.
@manniL Thanks, we are already investigating that workaround. Do we have some Nitro hook which runs before all server routes/middlewares where we can check the runtimeConfig
variable?
from nuxt.
One way could be solving this in userland with e.g. a runtimeConfig
value to check before executing the middleware/routes this in a layer π
from nuxt.
Start a new pull request in StackBlitz Codeflow.
from nuxt.
Thank you for your prompt response.
I attempted to implement a wrapper solution, but encountered several challenges. Simply checking within the server route proved ineffective, as the event handler continued to return 'false', even after an early return.
While using the wrapper, I observed two peculiar behaviors:
- When making a
GET
request via curl to the logout route, the server returns an error message (Invalid lazy handler result. It should be a function
) instead of serving the HTML. However, when accessing the same route through a browser, the page renders correctly. Here's the console error:
[nuxt] [request error] [unhandled] [500] Invalid lazy handler result. It should be a function:
at /dev/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:1617:17
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.handler (/dev/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:1697:19)
at async Server.toNodeHandle (/dev/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:1907:7)
- Incorporating the
defineCustomEventHandler
wrapper within the middleware causes the Nuxt application to fail to render anything, displaying the following console error instead:ERROR [worker reload] [worker init] Cannot read properties of undefined (reading 'handler')
.
You can verify this here: Updated Stackblitz
from nuxt.
Hello, thank you very much for the support.
I created an updated Stackblitz using the multi-app.
Multi-App Monorepo Stackblitz
from nuxt.
Hi :) I'm currently facing the same issue.
We're building about 10 websites, depending on the same OAuth provider. To simplify those websites, we've created a utils library, containing a notification helper, global styles etc. and a server API middleware, to exchange authentication tokens safely.
However, one of our website (the authentication website) doesn't need this middleware, as it's automatically redirecting users to other websites.
As a workaround, our library isn't using layer, but module, to allow configuring styles, authentication etc.
from nuxt.
You can disable server routes and middleware with a Nuxt hook:
export default defineNuxtConfig({
devtools: { enabled: true },
modules: [
function (_, nuxt) {
nuxt.hook('nitro:init', nitro => {
nitro.options.scanDirs = []
})
}
]
})
You could add this tiny module or hook into your capacitor app.
from nuxt.
Thank you for your feedback. I encountered an issue when settingscanDirs
to an empty array, as it also removes our Nitro route types, which our application's code relies on. Is there a way to selectively enable or disable a specific layer route or middleware?
from nuxt.
Related Issues (20)
- Tailwindcss added at last is not applied HOT 5
- Disabling SSR prevents remaining CSS from loading HOT 5
- Error: Cannot find module punycode/ HOT 9
- Img @error not working HOT 2
- useHead undefined after initiating a regex (since monday) HOT 4
- keepalive not work HOT 1
- String vs object errors with `createError` and accessing server-thrown errors on client
- Tailwind css issue related to CSS specificity on dev server HOT 1
- keep alive caches are destroyed when visit keep alive excluded page HOT 3
- The package generated under the .output/server/node_modules file is a hyperlink. HOT 2
- 'text/html' is not a valid JavaScript MIME type. HOT 2
- This module cannot be imported in the Vue part of your app. [importing @nuxt/kit from app.vue] causing page to not work HOT 5
- If a component uses empty data in `useFetch`, then `clearError` will be invalidated HOT 2
- Cache control header missing in response headers (while using nitro.publicAssets) HOT 7
- [nuxt] [request error] [unhandled] [500] _fetch is not a function HOT 3
- feat: support passing options to `TypedRouterOptions` when using `experimental.typedPages` HOT 7
- Dynamic layouts HOT 4
- Previous route info HOT 2
- Imported CSS files not correctly injected in circumstances involving lazy-loaded components HOT 1
- Nuxt 3 Dev build time is very slow in WSL 2 Linux Ubuntu ~ ranging up to 30 seconds just to refresh changes HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nuxt.