-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
SPA Documentation / Examples #92
Comments
Right now, using 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 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! |
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! |
Hey @spaceemotion I've been using a 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();
}); |
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. |
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. |
Prerequisites
Issue
Hi there 👋
I'm working on setting up fastify-vite in SPA mode, and I would like to use this plugin to serve my static build.
There are some comments in the README that suggest there is an SPA example, but it doesn't appear to exist. I'd be happy to contribute a PR with an example, but I'm a bit unsure on some of the requirements
When using fastify-vite to serve a built application, does a user always need to provide a server entrypoint as well? Looking at this example, the comment suggests that its required for SSR but I'm not sure about how SPAs fit in to the picture.
Thanks for your time and work on this plugin!
The text was updated successfully, but these errors were encountered: