fastify-dx
fastify-dx copied to clipboard
How to run code on the server
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
Issue
I'm playing around with this library to figure out how I would create something that I would normally use a SPA for.
Example
- a Web UI with an HTTP API which the client invokes, runs something on the server and returns some results
- let's also assume that what runs on the server cannot run on the client (e.g. a Node-only library which doesn't make sense running on the client)
What I did
- created a "API" module containing the code I would normally have in my backend API (let's say it's some Node.js code, e.g. DB access)
- created a new page which imports the API module
- set the page as server-only so that my API code doesn't run on the client
- use the API module in the
getData
export of the page module
Issues I encountered
- Vite cannot build the app because the API module cannot be built on the client (although the page where I use such code is set a serverOnly)
- Even assuming the API module code successfully builds on the client, how do I make it run on the server only, e.g. if it needs client inputs to run?