Deploy React App to Posit Connect with server.js


I just started working with Posit Connect and wanted to find out how one could deploy a React App.

Thanks to this post (Deploying React apps in RStudio Connect) and some work with sql.js I was capable deploying the app and loading the data appropriately. Yet, I also wanted to have a handleSubmit function for inserting data into the database, which then gets saved and retrieved by the Statistics component. The functions I used for that generally work, but it seems that the server.js script does not get handled by Posit connect so that it is able to conduct POST and GET requests. All in all, I do not see any console.log results appearing in my console when inspecting the app. I already made sure to server.js manually to the build folder I used as input for the reconnect-deployApp function.

All in all, I just want to know, if there is a specially way to handle the server.js script of a react app and its requests when using Posit. Has anybody already had any experience with that?

I wouldn't expect code depending on server.js to work on Connect; Connect does not run Node servers for you.

Okay, thank you for this information. I was wandering if there is a way to host a database on Posit Connect which takes new entries via a Form Component and uses the database for some visualizations based on the same database and is available for all users.
In general, my app offers a Form input to enter some observations users made and gives some descriptive statistics where and when these observations were made. Is there a way to set up a database for this with React and Posit connect?
Just including the database into the build folder when deploying the app might not be possible or would cause some issues with data integrity and data persistence I imagine.
Would be the best way, then, to use an API to host the server-side code on a separate server or to use a cloud-based database and connect it with the app?

See this article about working with data on Connect. You'll probably want to use an external database.