Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose local web server using ngrok #43

Merged
merged 11 commits into from
Jun 7, 2024
Merged
Binary file modified .DS_Store
mat-ng marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,37 @@ Open Prisma studio:
npx prisma studio
```

## Ngrok
### Set-up
1. Create an [ngrok](https://dashboard.ngrok.com/signup) account

2. Store your personal ngrok authentication token as an environment variable in the .env file of the root directory:
```bash
NGROK_AUTHTOKEN=${authtoken}
```

3. Run the application:
```bash
docker compose up --build
```

### Troubleshooting

If another service is occupying port 5001, identify the PID of the service:
```bash
sudo lsof -i :5001
```

Kill the occupying service:
```bash
sudo kill <PID>
```

Run the application again:
```bash
docker compose up --build
```

## The Team
### Term 1 (W24):
**Project Lead:** N/A<br>
Expand Down
12 changes: 9 additions & 3 deletions backend/typescript/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ COPY package.json yarn.lock tsconfig.json ./

RUN echo "deb http://archive.debian.org/debian stretch main" > /etc/apt/sources.list

# libcurl3 is required for mongodb-memory-server, which is used for testing
RUN apt-get update && apt-get install -y libcurl3
# Install dependencies
RUN apt-get update && apt-get install -y libcurl4 curl unzip

# Install ngrok using curl
RUN curl -o ngrok-stable-linux-amd64.zip https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && \
unzip ngrok-stable-linux-amd64.zip && \
mv ngrok /usr/local/bin/ && \
rm ngrok-stable-linux-amd64.zip

RUN yarn install

COPY . ./

RUN npx prisma generate

EXPOSE 5000
EXPOSE 5001
ENTRYPOINT ["yarn", "dev"]
4 changes: 2 additions & 2 deletions backend/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@prisma/client": "^5.11.0",
"@prisma/client": "^5.14.0",
"@types/graphql-upload": "^8.0.6",
"@types/json2csv": "^5.0.3",
"@types/multer": "^1.4.6",
Expand Down Expand Up @@ -74,7 +74,7 @@
"mongodb-memory-server": "^6.9.6",
"nodemon": "^2.0.7",
"prettier": "^2.2.1",
"prisma": "^5.11.0",
"prisma": "^5.14.0",
"ts-jest": "^27.0.3",
"typescript": "^4.1.5"
},
Expand Down
1 change: 1 addition & 0 deletions backend/typescript/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "linux-arm64-openssl-3.0.x"]
}

datasource db {
Expand Down
4 changes: 2 additions & 2 deletions backend/typescript/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ firebaseAdmin.initializeApp({
}),
});

app.listen({ port: process.env.PORT || 5000 }, () => {
app.listen({ port: process.env.PORT || 5001 }, () => {
/* eslint-disable-next-line no-console */
console.info(`Server is listening on port ${process.env.PORT || 5000}!`);
console.info(`Server is listening on port ${process.env.PORT || 5001}!`);
});
20 changes: 16 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ services:
- ./frontend:/app
- /app/node_modules
ports:
- 3000:3000
- "3000:3000"
environment:
- CHOKIDAR_USEPOLLING=true
env_file:
- ./frontend/.env

ts-backend:
container_name: de_ts_backend
build:
Expand All @@ -24,7 +25,7 @@ services:
- ./backend/typescript:/app
- /app/node_modules
ports:
- 5000:5000
- "5001:5001"
dns:
- 8.8.8.8
depends_on:
Expand All @@ -33,11 +34,12 @@ services:
env_file:
- ./.env
- ./backend/typescript/.env

db:
container_name: de_db
image: postgres:12-alpine
ports:
- 5432:5432
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data/
- ./db-init:/docker-entrypoint-initdb.d
Expand All @@ -46,10 +48,20 @@ services:
environment:
- POSTGRES_MULTIPLE_DATABASES=${POSTGRES_DB_DEV},${POSTGRES_DB_TEST}
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5

ngrok:
image: ngrok/ngrok:latest
platform: linux/arm64
command: ngrok http ts-backend:5001
ports:
- "4040:4040" # ngrok web interface
depends_on:
- ts-backend
environment:
- NGROK_AUTHTOKEN=${authtoken}
mat-ng marked this conversation as resolved.
Show resolved Hide resolved
volumes:
postgres_data:
Loading