navigate to your root directory and clone this repository with
git clone https://github.com/Ethanil/giftsnavigate to the backend-directory and create a virtual environment for python and activate it
cd gifts/gifts_backendpython3.10 -m venv .venvsource .venv/bin/activateyou will now see a (.venv) in front of your username in the console
install the packages with
pip install -r requirements.txtrename the .envExample into .env:
mv .envExample .envand edit it with your credentials
To use JWT we need a proper secret key. Make sure to use a apropriate key-length for the chosen Hashing-Algorithm.
- open the python interpreter by typing
py - Import secrets module with
import secrets - generate the token and print it with
print(secrets.token_urlsafe(32))[you can change the length here] - copy and paste it to your .env-file
To test that everything worked start the backend-server
uvicorn main:app --host 0.0.0.0 --port 5000if you want to test some more start another console and use
curl 127.0.0.1:5000/api/itemsthen stop the uvicorn-process with ctrl+c
deactivate the python-virtual-environment before proceding with
deactivateNavigate into your service.d directory with
cd ~/etc/services.d/And create a gifts_backend.ini with
nano gifts_backend.inipaste the following code into it
[program:gifts_backend]
directory=%(ENV_HOME)s/gifts/gifts_backend
command=%(ENV_HOME)s/gifts/gifts_backend/.venv/bin/uvicorn main:app --host 0.0.0.0 --port 5000
autostart=true
autorestart=true
stdout_logfile=%(ENV_HOME)s/logs/gifts_backend.log
save and close with ctrl+o followed by enter and then ctrl+x
expose the service to the outside(make sure to use the correct port and route):
uberspace web backend set /api --http --port 5000Navigate to the frontend and install the packages with
npm installif this is not working for you try yarn instead:
yarn installrename the .envExample:
mv .envExample .envand edit your credentials
Build the frontend
npm run buildyou can replace here npm with yarn aswell
you know should have an .output/server/index.mjs file. This is the entry-point of the node server.
Navigate into your service.d directory with
cd ~/etc/services.d/And create a gifts_frontend.ini with
nano gifts_frontend.inipaste the following code into it
[program:gifts_frontend]
directory=%(ENV_HOME)s/gifts/gifts_frontend
command=node .output/server/index.mjs
autostart=true
autorestart=true
environment=NITRO_PORT=8000
stdout_logfile=%(ENV_HOME)s/logs/gifts_frontend.log
save and close with ctrl+o followed by enter and then ctrl+x
expose the service to the outside(make sure to use the correct port and route):
uberspace web backend set / --http --port 8000Alternatively you can create one group for both supervisord systems:
[group:gifts]
programs=gifts_frontend,gifts_backend
[program:gifts_backend]
directory=%(ENV_HOME)s/gifts/gifts_backend
command=%(ENV_HOME)s/gifts/gifts_backend/.venv/bin/uvicorn main:app --host 0.0.0.0 --port 5000
autostart=true
autorestart=true
stdout_logfile=%(ENV_HOME)s/logs/gifts_backend.log
[program:gifts_frontend]
directory=%(ENV_HOME)s/gifts/gifts_frontend
command=node .output/server/index.mjs
autostart=true
autorestart=true
environment=NITRO_PORT=8000
stdout_logfile=%(ENV_HOME)s/logs/gifts_frontend.log
reread the config
supervisorctl rereadupdate the services
supervisorctl updateafter a few seconds you should see the process running with
supervisorctl statuscheck the backend port-routing with
uberspace web backend listboth ports should have an OK-status
INSERT into newSchema.user (avatar, email, firstName, lastName, password, onlyViewing)
SELECT LOWER(u.email) as avatar, LOWER(u.email) as email, u.fullname as firstName, '' as lastName, u.password as password, false as onlyViewing
FROM oldSchema.users u;Add any kind of Lastname to users to not have ugly gaps in listnames
INSERT INTO newSchema.giftGroup (id, editable, isSecretGroup, name)
SELECT u.userid as id, false as editable, false as isSecretGroup, CONCAT(eu.firstName, ' ', eu.lastName, '''s Liste') as name
FROM oldSchema.users u join newSchema.user eu on u.fullname = eu.firstName;INSERT INTO newSchema.isBeingGifted (giftGroup_id, user_email)
SELECT userid as id, LOWER(u.email) as user_email
FROM oldSchema.users u;INSERT INTO newSchema.gift (name, price, giftStrength, link, description, picture, giftGroup_id, user_email, freeForReservation)
SELECT description AS name, price, ranking AS giftStrength, url AS link, oldSchema.items.comment AS description, COALESCE(image_filename,'') AS picture, items.userid as giftGroup_id, LOWER(email) as user_email, false as freeForReservation
FROM oldSchema.items join oldSchema.users u on items.userid = u.userid;make sure to copy the pictures of the gifts from the old directory into the one you chose in the .env of the backend!
INSERT INTO newSchema.has_reserved(gift_id, user_email)
SELECT g.id as gift_id, LOWER(u.email) as user_email
FROM oldSchema.allocs join oldSchema.items i on allocs.itemid = i.itemid join oldSchema.users u on allocs.userid = u.userid join newSchema.gift g on g.name = i.descriptionNavigate into your project directory(gifts)
Check if there are any updates with
git fetch
git statusif there are new/changed files this will show it
pull the changes with
git pull
navigate into frontend-directory and run the install and build again with npm:
npm install
npm run build
or with yarn:
yarn install
yarn run build
Restart the supervisore daemons with
supervisorctl restart gifts_frontend
supervisorctl restart gifts_backend
or if those are the only 2 daemons running:
supervisorctl restart all
or if you used the alternative setup:
supervisorctl restart gifts:*