Comments (5)
Hey @spaceemotion
I've been using a *
as a fallback route that serves my SPA. If no other paths match, we render the application and let the client take over. Heres an example plugin
module.exports = fp(async function (app, opts) {
await app.register(vite, {
root: import.meta.url,
dev: process.env.NODE_ENV !== "production",
spa: true,
});
app.get("*", async (request, reply) => {
return reply.html();
});
await app.vite.ready();
});
from fastify-vite.
I'm this close to being able to work on the new documentation suite — I'll be essentially reusing the same template I'm working on for the new Fastify DX docs. I definitely need to expand the docs on this area, will keep this issue open until I do.
from fastify-vite.
Right now, using spa: true
changes the Reply.html()
method to deliver the static index html (both in dev, with the necessary dev transformations, and in production, serving index.html from the production bundle).
import Fastify from 'fastify'
import FastifyVite from '@fastify/vite'
const server = Fastify()
await server.register(FastifyVite, {
spa: true,
root: import.meta.url,
})
await server.vite.ready()
server.get('/', (req, reply) => {
reply.html()
})
Note that when using spa: true
, you don't have to provide createRenderFunction
.
I'll gladly accept a PR that adds this piece of information to the README.
I'm crazy busy trying to sort out Fastify DX's last remaining issues!
from fastify-vite.
So I got an SPA setup working for a vue3 application I am working on, but whenever I reload the browser, fastify obviously can't find the routes, as they're being handled client-side. I don't need server side rendering for this project.
my config looks pretty much what your suggestion shows.
Is this something that's still being worked on? Or do I have to provide some kind of hints to fastify to handle this properly? is there a fallback route I can use to e.g. say "if there's no route, use the frontend"?
thanks in advance!
from fastify-vite.
Thanks for the hard work so far! I was eventually able to cobble together a working version. The only other problem I ran into was that fastify did not detect that the port I was trying to listen to, was already in use. But that's unrelated and not part if this issue :)
If it helps: as a general feedback, I found the current documentation on this project a bit confusing as I have never used fastify before (this was my first time trying to combine both vite and fastify into one server). As such the current README was a bit overwhelming, but the examples folder worked well enough.
from fastify-vite.
Related Issues (20)
- Files in /public folder are not served in production mode HOT 4
- Error on Windows: TypeError: Cannot read properties of null (reading 'replace')
- Websocket can not connect when using https fastify
- If vites config contains `defineConfig` with callback, then SSR is broken HOT 3
- How to configure multi-page entry
- Issues running with fastify-compress HOT 4
- Serve static assets from ssr builds in production mode HOT 2
- TypeError [ERR_INVALID_ARG_TYPE]: The "paths[0]" argument must be of type string
- Trace: The CJS build of Vite's Node API is deprecated
- Conflicting websockets between vite and `@fastify/websocket` causing infinite redirects HOT 1
- [react][windows] React Starter Template does not start on Windows HOT 4
- How to use Vue plugins like instance.use(...) HOT 4
- NPM install fails with 'edgesout' error HOT 3
- [SPA] allowing passing additional context to the render function HOT 3
- mts file extension is not supported for vite.config HOT 3
- @fastify/vue Smart Import doesn't resolve path in windows HOT 5
- SPA mode results in `Cannot read properties of null`
- Move `fastify` and `vite` to peer dependencies
- Missing `fastify-plugin` dependency
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 fastify-vite.