Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Nitro features like Cache API, Storage Layer, or Auto Imports? #131

Open
frenzzy opened this issue Jan 16, 2024 · 11 comments
Open
Labels
question Further information is requested

Comments

@frenzzy
Copy link

frenzzy commented Jan 16, 2024

Is it even possible?

Sorry, but it's not clear to me from the docs or source code whether Nitro is used under the hood or not.

Nitro offers some really cool built-in features like:

Could anyone provide an example of using any Nitro feature?
It would be really helpful, or should I reimplement them myself?

@nksaraf
Copy link
Owner

nksaraf commented Jan 28, 2024

Nitro IS used under the hood, but not completely exposed. You can configure most nitro options through createApp's server option, eg.

import { createApp } from "vinxi";

export default createApp({
	server: {
		https: true
	}
});

As per the individual APIs you have listed, each has its own reason for not being included in the API currently.

  1. Storage Layer: It's just unstorage. You can install it yourself and set it up. Its pretty trivial.
  2. Auto Imports: We have disabled this, but you can enable it by using unimports vite plugin.
  3. Cache API: This one I want to include, still figuring out how, in the meanwhile cache headers can help you out.

What other features of nitro would you like me to give you an idea bout its availability.

@nksaraf nksaraf added the question Further information is requested label Jan 28, 2024
@doeixd
Copy link
Contributor

doeixd commented Jan 29, 2024

Is it possible to register a nitro plugin?

@nksaraf
Copy link
Owner

nksaraf commented Jan 29, 2024

yup.. nitro plugins can be added as they are in nitro thru the server config in vinxi

@edivados
Copy link
Contributor

edivados commented Jan 29, 2024

I am assuming you are supposed to get defineNitroPlugin from #internal/nitro? That seems to only work in build or I am doing something wrong. Nvm does not work in dev.
https://stackblitz.com/edit/solidjs-solid-start-8rmaag?file=src%2Fplugin.ts (Solid-Start)

@nksaraf
Copy link
Owner

nksaraf commented Jan 30, 2024

Ohh damn yeah I forgot I had not implemented it in dev yet. Lemme fix that and push today.

@niicojs
Copy link

niicojs commented Jan 30, 2024

I've added auto import to server and client, it's as easy as adding unimport/plugin to the vite config in app.config. Good stuff!
For some reason however, I can't make it work on api routes (through api router).

Update; for an individual api handler, just using unimport works fine. Seems not that easy with apiRouter from @vinxi/router/api

@nksaraf
Copy link
Owner

nksaraf commented Jan 30, 2024

are you able to add plugins to apiRouter, pass in plugins to the function that creates the router and you should be able to use unimports there too.. is this not working.. bump everything to latest versions (0.2.1). You might have to make some changes to the config eg. mode will become type. mode: "build" becomes type: "client" and mode: "handler" becomes type: "http"

@niicojs
Copy link

niicojs commented Jan 30, 2024

Doesn't seems to work.
Just update to latest and same thing.

Is it because plugins are executed on api-handler.js but not on individual files loaded by the api router?
The plugin is loaded (I can see the .d.ts beeing generated), but not executed on files in my api folder

@nksaraf
Copy link
Owner

nksaraf commented Jan 31, 2024

Haven't fixed the plugins in dev yet. Will do that soon. Couldn't get enough time the last few days

@remonke
Copy link

remonke commented Feb 8, 2024

No please for the love of God do not include auto-imports, it's the biggest piece of crap I have ever seen in my life, and it would ruin this beatiful project.

@steschi
Copy link

steschi commented Apr 23, 2024

Haven't fixed the plugins in dev yet. Will do that soon. Couldn't get enough time the last few days

Was trying to use nitro-plugins with vinxi. I guess they are not yet supported in dev-mode. Do you think this will be a lot of work? Is there a way I could help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

7 participants