Wishlist/ HTML and java source
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
2.9 KiB

  1. # Developing for Wishlist/
  2. 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.
  3. 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.
  4. ## nginx stuff
  5. nginx is a systemd service, so to control it use:
  6. * `systemctl start nginx ` - starts nginx
  7. * `systemctl stop nginx ` - stops nginx
  8. * `systemctl restart nginx` - restarts nginx
  9. * `systemctl status nginx ` - get nginx status
  10. 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 `http://127.0.0.1:8027` (That's the container itself).
  11. ## Webdev stuff
  12. 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`.
  13. If you just want to do web development simply run `cd /opt/; java -jar Wishlist.jar`
  14. ## Backend stuff
  15. 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.
  16. 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:
  17. ```
  18. #location /api/ { #any requests to /api will be forwarded to localhost:8222, which is the java backend
  19. # proxy_pass http://127.0.0.1:8027;
  20. #}
  21. location /api/ {
  22. proxy_pass http://10.0.3.1:8027;
  23. }
  24. ```
  25. > Note: you might have to change `10.0.0.3.1` if you machine was given a different IP address for the virtual LXC network adapter, check with `ip a`
  26. 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.