I'm still writing a web meta-framework, writing documentation, and prepping for a "How To Make a Nim Website" video series.
I'm starting to document how to get the compiled executable online for production use. I can think of dozens of ways, but I'd like to ask the community:
What methods have you used? Any gotchas or bits of advice?
Possible useful information:
If for the backend:
Since this is a forum, all answers help everyone. I'm not asking for "best practice" per se. I suspect there are not enough web sites out there yet to come to that kind of conclusion.
My answers in relation to this forum:
Did you use nim for the backend (using jester etc.), the frontend (javascript, etc.), or both?
Jester/Karax
Did you use a container such as Docker? Which kind?
Nope
What web server software did you front it with? (Apache, NGINX, etc?)
Nginx
Did you host any DB (MySQL, etc.) or Messaging (RabbitMQ, etc) yourself or did you use a cloud service?
Only SQLite
Which hosting company did you work with? Is the web site on a single instance, or have you gotten it to work in a cluster?
Digital Ocean, Single instance.
Store your nim source in a repo mixed in with your assets (CSS, images, etc.)? How did you separate for production?
Yep. I created a custom piece of code that mixes the styles. I can go into detail if you want.
I have been working on a high productivity PWA framework when time allows.
It has an Orm for asyncpg.
I will use Nginx with hosting most likely at Vultr.
For JS backend I'm most likely going to use React instead of Karax because there is more debugging tooling and ready made components. Maybe something like Atlas Kit or Ant Design.
I been working on my website. Its not done yet. The plan may change. This is what I am doing now.
I am a huge fan of static code+assets in S3 and behind CloudFlare. The only way they communicated with the server is through a WebSocket server that is behind Nginx. WebSocket + 100% static site is my mo. No REST or AJAX.
Did you use nim for the backend (using jester etc.), the frontend (javascript, etc.), or both? Using nim for both.
Did you use a container such as Docker? Which kind? Nope. I don't believe in containers. Nim already ships very small binaries. VPS is already a container.
What web server software did you front it with? (Apache, NGINX, etc?) Nginx infront of Nim WebSocket Server, S3+CloudFlare for all static content including Nim client side code.
Did you host any DB (MySQL, etc.) or Messaging (RabbitMQ, etc) yourself or did you use a cloud service? MySql hosted myself, main backup to S3, separate backup with Digital.
Which hosting company did you work with? Is the web site on a single instance, or have you gotten it to work in a cluster?
Digital Ocean, Single instance. Nim is very fast an efficent. Digital Ocean is really good.
Store your nim source in a repo mixed in with your assets (CSS, images, etc.)? How did you separate for production?
Everything lives in one repo: images, sounds, short videos (gifs). My CSS, if you can call it that, is generate by nim code.
Did you use nim for the backend (using jester etc.), the frontend (javascript, etc.), or both?
I used Nim for backend with Jester, for templates with Source Code Filters, and for scripting with JS target.
Did you use a container such as Docker? Which kind?
I ran the app in Docker container with Docker Compose.
What web server software did you front it with? (Apache, NGINX, etc?)
Didn't have any load (it's a personal app that only my wife and I used), so I didn't use any server apart from Jester's own. If I had to, I'd use Nginx as another service in Docker Compose.
Did you host any DB (MySQL, etc.) or Messaging (RabbitMQ, etc) yourself or did you use a cloud service?
Just SQLite.
Which hosting company did you work with? Is the web site on a single instance, or have you gotten it to work in a cluster?
Again, it's a small app, so I hosted it on an Azure VM.
Store your nim source in a repo mixed in with your assets (CSS, images, etc.)? How did you separate for production?
All in one repo.
I am running 8 websites in production environments and all with Nim as the backend.
I have 3 different setups for maintaining and updating the websites:
At the moment I am in the process of moving a couple of websites from Wordpress to NimWC. This will be done with classic cloning of repository and compiling on the server.
I have been hosting a MQTT broker with https://github.com/barnybug/nim-mqtt and https://github.com/tekjar/nimqtt-protocol. But they could not be integrated properly with async in my setup, so I have moved to Mosquitto, where Nim just reads the output stream. This is integrated with my Nim program and running in production at the moment.
I am hosting a websocket with https://github.com/niv/websocket.nim , which works smoothless with my website based on https://github.com/ThomasTJdev/nim_homeassistant.
Did you use nim for the backend (using jester etc.), the frontend (javascript, etc.), or both?
Jester & old school JS
Did you use a container such as Docker? Which kind?
Nope.
What web server software did you front it with? (Apache, NGINX, etc?)
Nginx.
Did you host any DB (MySQL, etc.) or Messaging (RabbitMQ, etc) yourself or did you use a cloud service?
Depends on the website. SQLite locally (for small websites and quick deployment) & Postgres in the cloud and locally,
Which hosting company did you work with? Is the web site on a single instance, or have you gotten it to work in a cluster?
AWS, single instance, Nas and RPi's.
Store your nim source in a repo mixed in with your assets (CSS, images, etc.)? How did you separate for production?
Mixed. I use option 1 & 3 above to separate the files.
Fast forward to 2021! I wrote Todo Network (https://todo.network) in Nim.
Did you use nim for the backend (using jester etc.), the frontend (javascript, etc.), or both?
Jester and Karax both on the backend, sending AJAX requests via Htmx.
Did you use a container such as Docker? Which kind?
No, the setup is too basic.
What web server software did you front it with? (Apache, NGINX, etc?)
Nginx.
Did you host any DB (MySQL, etc.) or Messaging (RabbitMQ, etc) yourself or did you use a cloud service?
DB: PostgreSQL. Cloud provider: AWS Lightsail.
Is the web site on a single instance, or have you gotten it to work in a cluster?
Single instance, too small for a cluster.
Store your nim source in a repo mixed in with your assets (CSS, images, etc.)? How did you separate for production?
Yes, a single Git repo. I use shell scripts to set env vars, with separate scripts for dev and Production. The code picks up the env vars and acts accordingly.
Sure, here's the Karax (back-end) to display an input field that uses autocomplete. The autocomplete is handled via a post request at URL "/data/search" which returns HTML. This HTML is sent to the div with id "search-results".
input(class = "input",
type = "text",
id = "schedule_date",
name = "s",
size = "20",
maxlength = "20",
placeholder = "Day DD Mon YYYY",
value = schedule_date_value,
hx-post = "/date/search",
hx-trigger = "keyup changed delay:500ms",
hx-target = "#search-results",
hx-indicator = ".htmx-indicator",
style = style((StyleAttr.display, "inline-block"),
(StyleAttr.verticalAlign, "top")))
The hx-x fields are recognized Karax attributes. See the Htmx examples for more of what you can do: https://htmx.org/examples