#How can I expose specific functions in the server build?

1 messages · Page 1 of 1 (latest)

faint prairie
#

Scenario: I have a Remix app deployed using Node.js and I've turned the server.js runner (that imports the Remix build module) into a CLI app (with a serve command that runs the server).

I'd like to add admin commands such as create-account or clear-sessions to the server.js runner that I can run in production. To do that I want to call specific functions defined in my app/db.server.ts file. Thus, I'd like to have those specific functions be included and exported in the build module so I can access them in my production environment. Does anyone know of a way to do that?

Alternatively, would someone recommend another approach to implementing one-off (privileged) admin actions for production?

surreal dove
#

The easiest solution is to just create an endpoint for each of them that checks an Authorization header against an api key, you can just generate a random string and set it as an environment variable in your prod environment

#

then you can make authorized api calls from any rest client (or in the future, an admin UI)

#

Remix doesn't have anything built in to expose functions this way, but if you've basically built your own CLI tool, then nothing stops you from adding extra commands that import from your app/db.server.ts file