Comments (5)
closing this as I just figured out a way to make fastify works with this plugin. It's released in 0.0.10, please try it out!
from vite-plugin-node.
So far so good! Works great, super fast and reloading seems to work too. Thanks I really appreciate it!
from vite-plugin-node.
This seems to work. By default in Fastify 3 it doesn't support connect style middleware.
import chalk from 'chalk';
import debug from 'debug';
import fastify, { FastifyInstance } from 'fastify';
import { Server } from 'http';
import middie from 'middie';
import { IServer } from 'vite-plugin-node';
export const debugFastify = debug("vite:node-plugin:fastify");
export const FastifyServer: IServer<FastifyInstance> = {
_app: undefined,
_server: undefined,
_config: undefined,
async create(server, config) {
this._config = config;
const { createViteNodeApp } = await server.ssrLoadModule(
this._config.appPath
);
this._app = createViteNodeApp as FastifyInstance;
await this._app.register(middie);
this._app.use(server.middlewares);
debugFastify(chalk.dim`app created`);
},
async start() {
await this._app?.listen(this._config?.port as number);
debugFastify(chalk.dim`server started at port ${this._config?.port}`);
this._server = this._app;
},
async close() {
await (this._server as Server)?.close();
debugFastify(chalk.dim`server closed`);
},
async restart() {
debugFastify(chalk.dim`server restarting`);
if (this._server) {
await this.close();
}
await this.start();
},
};
from vite-plugin-node.
I'm working on this as well. I got the below to work at least for the basics....still have to do more digging into it but this could be fantastic to use vite
createCustomServer: () => {
const FastifyServer: IServer<FastifyInstance, Server> = {
_app: undefined,
_server: undefined,
_config: undefined,
async create(server, config) {
this._config = config;
const { createViteNodeApp } = await server.ssrLoadModule(this._config.appPath);
this._app = (await createViteNodeApp) as FastifyInstance;
console.debug(`app created`);
},
async start() {
console.log('server starting');
await this._app?.listen(this._config?.port as number);
console.debug(`server started at port ${this._config?.port}`);
this._server = this._app;
},
async close() {
console.debug('app trying to close');
if (this._app && this._server) {
// await this._app?.close();
await this._server.close();
}
console.debug(`server closed`);
},
async restart() {
console.debug(`server restarting`);
await this.close();
await this.start();
},
};
return FastifyServer;
},
from vite-plugin-node.
Hi @delaneyj @erossdev, thanks for your interest to use this plugin. I recently rewrote how this plugin works to make it faster by not restarting the server on file update. If you care to know more detail, see https://github.com/axe-me/vite-plugin-node#how
While I was rewriting it, I tried to add fastify support. Unfortunately, due to I never used it and didn't find a way how can I by pass a node HTTP request to its app in short time, in the new release I still not have it included. Any helps from you fastify experts would be appreciated.
The basic idea is I need to pass down all the requests from one fastify app to another, something like:
fastify.addHook('onRequest', async (req, res) => {
// get the latest app instance
const { viteNodeApp } = await server.ssrLoadModule(config.appPath)
// pass down requests, here is where I don't know how to implement in fastify
viteNodeApp(req, res)
})
from vite-plugin-node.
Related Issues (20)
- Nest.js + Fastify: No driver (HTTP) has been selected. HOT 2
- HMR only works after the application web page is reloaded HOT 2
- Add support for Vite 5 HOT 3
- not support parameter decorators HOT 5
- Nest middleware not receiving express Request
- Expose viteNodeApp after async operations HOT 2
- HMR reloads from root - app.ts
- Proposal: Simpler way to bundle Node apps with Vite HOT 1
- NestJS example not working HOT 3
- Can it bundle into a single file?
- `vite build` does not bundle the dependencies HOT 3
- HMR not working, server going through a full reload every time a file changes
- Configuring https server results in an exception HOT 3
- server example HOT 1
- `vite-plugin-node` vs `vite-node` HOT 2
- How to render some routes using Nest and some using Vite? HOT 1
- HMR doesn't work HOT 3
- NestJs Build error - Failed to resolve entry for package "fs"
- I used the nestjs and vite-plugin-node example, they threw this err,,,what makes it so HOT 2
- Module '"http"' has no default export. HOT 2
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 vite-plugin-node.