diff --git a/back/package.json b/back/package.json index 0ce3f9f..c94bd38 100644 --- a/back/package.json +++ b/back/package.json @@ -10,8 +10,8 @@ "build": "nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "start": "nest start", - "start:dev": "nest start --watch", - "start:debug": "nest start --debug --watch", + "start:dev": "nest start --watch --preserveWatchOutput", + "start:debug": "nest start --debug --watch --preserveWatchOutput", "start:prod": "node dist/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index f4b8398..57c2455 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -40,13 +40,14 @@ services: retries: 5 ports: - "5432:5432" + front: build: context: ./front dockerfile: Dockerfile.dev environment: - SCOROMETER_URL=http://scorometer:6543/ - - NGINX_PORT=80 + - NGINX_PORT=4567 ports: - "19006:19006" volumes: @@ -55,3 +56,19 @@ services: - "back" env_file: - .env + + nginx: + image: nginx + environment: + - API_URL=http://back:3000 + - SCOROMETER_URL=http://scorometer:6543 + - FRONT_URL=http://front:19006 + - PORT=4567 + depends_on: + - back + - front + volumes: + - "./front/assets:/assets:ro" + - "./front/nginx.conf.template.dev:/etc/nginx/templates/default.conf.template:ro" + ports: + - "4567:4567" diff --git a/docker-compose.yml b/docker-compose.yml index af5e44b..eb054e8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -35,11 +35,7 @@ services: retries: 5 front: - build: - context: ./front - args: - - API_URL=${API_URL} - - SCORO_URL=${SCORO_URL} + build: ./front environment: - API_URL=http://back:3000/ - SCOROMETER_URL=http://scorometer:6543/ diff --git a/front/Dockerfile b/front/Dockerfile index 34b510e..c219a27 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -22,6 +22,7 @@ RUN yarn tsc && expo build:web # Serve the app FROM nginx:1.21-alpine COPY --from=build /app/web-build /usr/share/nginx/html -COPY nginx.conf.template /etc/nginx/conf.d/default.conf.template +COPY ./assets/ /usr/share/nginx/html/assets/ +COPY nginx.conf.template /etc/nginx/templates/default.conf.template -CMD envsubst '$API_URL $SCOROMETER_URL $NGINX_PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;' +CMD nginx -g 'daemon off;' diff --git a/front/assets/metronome.mp3 b/front/assets/metronome.mp3 new file mode 100644 index 0000000..dfdf644 Binary files /dev/null and b/front/assets/metronome.mp3 differ diff --git a/front/components/Metronome.tsx b/front/components/Metronome.tsx new file mode 100644 index 0000000..8e1e7ab --- /dev/null +++ b/front/components/Metronome.tsx @@ -0,0 +1,13 @@ +import { useEffect, useRef } from 'react'; + +export const Metronome = ({ paused = false, bpm }: { paused?: boolean; bpm: number }) => { + const ref = useRef(null); + useEffect(() => { + const int = setInterval(() => { + if (!ref.current) ref.current = new Audio("/assets/metronome.mp3"); + ref.current.play(); + }, 60000 / bpm); + return () => clearInterval(int); + }, []); + return null; +}; diff --git a/front/nginx.conf.template b/front/nginx.conf.template index 9baf3ed..fc5af83 100644 --- a/front/nginx.conf.template +++ b/front/nginx.conf.template @@ -4,6 +4,10 @@ server { index index.html; + location /assets { + alias ./assets; + } + location / { try_files $uri $uri/ /index.html; } diff --git a/front/nginx.conf.template.dev b/front/nginx.conf.template.dev new file mode 100644 index 0000000..b7caf3b --- /dev/null +++ b/front/nginx.conf.template.dev @@ -0,0 +1,29 @@ +server { + listen ${PORT}; + root /usr/share/nginx/html; + + index index.html; + + location /assets { + alias /assets; + } + + location / { + proxy_pass ${FRONT_URL}/; + } + + location /api/ { + proxy_pass ${API_URL}/; + } + + location /ws { + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Scheme $scheme; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_pass ${SCOROMETER_URL}; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $http_connection; + proxy_http_version 1.1; + } +} diff --git a/front/views/PlayView.tsx b/front/views/PlayView.tsx index 790a556..962e05b 100644 --- a/front/views/PlayView.tsx +++ b/front/views/PlayView.tsx @@ -33,6 +33,7 @@ import { MIDIAccess, MIDIMessageEvent, requestMIDIAccess } from '@motiz88/react- import * as Linking from 'expo-linking'; import url from 'url'; import { PianoCanvasContext, PianoCanvasMsg, NoteTiming } from '../models/PianoGame'; +import { Metronome } from '../components/Metronome'; type PlayViewProps = { songId: number; @@ -357,6 +358,8 @@ const PlayView = ({ songId, type, route }: RouteProps) => { {!partitionRendered && } + +