fastify / fastify-dx

Archived
903 stars 43 forks source link

How to run code on the server #43

Closed simoneb closed 2 years ago

simoneb commented 2 years ago

Prerequisites

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

What I did

  1. 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)
  2. created a new page which imports the API module
  3. set the page as server-only so that my API code doesn't run on the client
  4. use the API module in the getData export of the page module

Issues I encountered

  1. 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)
  2. 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?