Skip to content

Commit

Permalink
Merge pull request #5 from easymirror/add-basics
Browse files Browse the repository at this point in the history
Webapp
  • Loading branch information
Matthew17-21 authored Mar 23, 2024
2 parents 4652fde + 39f5b99 commit 94a847c
Show file tree
Hide file tree
Showing 74 changed files with 31,044 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/.env
**/.git
**/.gitignore
README.md
node_modules
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The base URL for local dev
REACT_APP_BASE_URL_DEV=""

# The base URL for production
REACT_APP_BASE_URL_PROD=""
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,5 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.DS_Store
.env.production
19 changes: 19 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Use a Node.js image
FROM node:latest

# Set the working directory
WORKDIR /app

# Copy the package.json and package-lock.json files
COPY package*.json yarn.lock ./

# Install dependencies
RUN yarn install

# Copy everything to the container
COPY . .

# Expose port
EXPOSE 3000

CMD ["yarn", "start" ]
33 changes: 33 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# =============================================================================
# Build phase
# =============================================================================
# Use a Node.js image
FROM node:latest AS builder

# Set the working directory
WORKDIR /app

# Copy the package.json and package-lock.json files
COPY package*.json yarn.lock ./

# Install dependencies
RUN yarn install

# Copy everything to the container
COPY . .

# Generate build files
RUN yarn build:prod

# =============================================================================
# Production Phase
# =============================================================================
# We specifify the platform because of compatibility issues when Mac Chips
# More info: https://stackoverflow.com/questions/74705475/aws-ecs-exec-usr-local-bin-docker-entrypoint-sh-exec-format-error
FROM --platform=linux/amd64 nginx:latest

COPY --from=builder /app/build /usr/share/nginx/html
COPY nginx/nginx.conf /etc/nginx/nginx.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
# easymirror-frontend
Source code to EasyMirror's frontend
Source code to EasyMirror's frontend.

## Building
### Dev
1) Run the [bash file](/build/dev_build.sh) found in [build directory](/build/). This ensures the `.env` file is also passed in.
2) For a manual build, run: `$ docker build -t easymirror-platform-frontend:latest .`

### Production
1) Run the [build bash file](/build/prod_build.sh) found in [build directory](/build/). This ensures the `.env` file is also passed in.
2) For a manual build, run: `$ docker build --file Dockerfile.prod -t easymirror-platform-frontend:latest .`

## File structure
- The file structure was inspired by this [WebDevSimplified article](https://blog.webdevsimplified.com/2022-07/react-folder-structure/).

Folder | Description | Example
------------- | ------------- | -------------
`src/assets ` | Contains everything that isn’t code related | images, css files, font files, etc
`src/components ` | Contains subfolder(s) of general components that are used throughout the app | Checkbox Component
`src/layouts ` | Folder for placing any layout based components | Navbar, Sidebar, etc
`src/lib` | Contains wrappers for the various different libraries you use in your project | Wrapping for `fetch()` calls
`src/pages ` | Contains all pages, one file for each | A home page file
`src/services ` | Contains all your code for interfacing with any external API. | File for collecting fingerprint data
`src/utils ` | Contains all utility functions. | Formatters like converting string to type Date

## TODOS
- [x] The client (Front end) will store refresh token in an httponly cookie and access token in local storage.
- [x] Display mirror link after successfully uploading file
- [x] Fix Modal background color
- [x] Display page for mirror host links
- [ ] Functionality to delete history
- [ ] Easier to way get domain name for dev/prod
- [ ] Mobile support (CSS)
4 changes: 4 additions & 0 deletions build/dev_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

echo "Building container for dev build..."
docker-compose -f ./docker-compose.yml up -d
6 changes: 6 additions & 0 deletions build/prod_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

echo "Building container for a production build..."
docker build \
--file Dockerfile.prod \
-t easymirror-platform-frontend:latest .
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3'

services:
frontend:
build:
context: .
dockerfile: Dockerfile.dev
image: easymirror-platform-frontend:latest
ports:
- "3000:3000"
env_file:
- .env
26 changes: 26 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '[$time_local] [$remote_addr - $remote_user] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
sendfile_max_chunk 1m; # Limits chunks to 1 Megabytes
keepalive_timeout 60;
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
}
Loading

0 comments on commit 94a847c

Please sign in to comment.