Browse Source

Wrote a readme for the LXC container

Thomas Withiam 3 years ago
  1. 42


@ -0,0 +1,42 @@
# Developing for Wishlist/
wishlist/ uses a proper web server to handle hosting of static files (those that are not dynamically generated) and to handle https (so that we don't have to manage certs in java). This LXC container runs nginx as the webserver, which reverse-proxies (forwards the http request to another server) any url request to `/api` to the java backend.
To actually visit the page hosted by nginx type the IP address of the container in your web browser. To find out what the address of the container is type `ip a` in a terminal in the container.
## nginx stuff
nginx is a systemd service, so to control it use:
* `systemctl start nginx ` - starts nginx
* `systemctl stop nginx ` - stops nginx
* `systemctl restart nginx` - restarts nginx
* `systemctl status nginx ` - get nginx status
The nginx config you most likely care about is `/etc/nginx/sites-enabled/default`, this is where I set nginx to load from `/var/www/html` and to proxy `/api` to `` (That's the container itself).
## Webdev stuff
I've configured nginx to host from `/var/www/html/` by default (since the git repo contains `html/` by default I've cloned it into `/var/www`). So if a web browser requests `http://IP_ADDRESS:PORT/favicon.ioc` nginx will try to load `/var/www/html/favicon.ico`. This directory can be worked on from your host operating system, on my machine `/var/www/html` was accessible from `/var/lib/lxc/wishlist/rootfs/var/www/html`. If you install lxc from snap you will find this in a different directory probably somewhere in `/var/snap`.
If you just want to do web development simply run `java -jar /opt/Wishlist.jar`
## Backend stuff
If you want to develop the backend I'd recommend loading the source in an IDE like eclipse or intelij and starting it. The backend loads a config file next to the executable (which if it's not present it will auto-generate, the autogenerated config puts the database right next to it as well). In an IDE the `bin/` folder in the project folder is likely where the config file and database (If you don't specify otherwise in the config file) will be generated.
To make nginx reverse-proxy to it edit `/etc/nginx/sites-enabled/default` and comment out the first `location /api/` section (with `#`) and uncomment the second section so that portion of the config looks like this:
#location /api/ { #any requests to /api will be forwarded to localhost:8222, which is the java backend
# proxy_pass;
location /api/ {
> Note: you might have to change `` if you machine was given a different IP address for the virtual LXC network adapter, check with `ip a`
This makes it so nginx in the container proxies back to your host OS and connections to `api/` are forwarded to port `8027` on your own machine, which the java backend handles with the good old sun HttpServer class. The port can be set in the config files mentioned above.