Skip to content

Commit

Permalink
Continuing work to get the frontend up and running (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviesgeek authored Aug 31, 2024
1 parent 99f2c8e commit ae9282f
Show file tree
Hide file tree
Showing 12 changed files with 1,392 additions and 45 deletions.
1 change: 1 addition & 0 deletions Caddyfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ localhost {
reverse_proxy meshinfo:9000
}
handle_path /next/* {
rewrite * /next{uri}
reverse_proxy frontend:80
}
handle /* {
Expand Down
1 change: 1 addition & 0 deletions Caddyfile.sample
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ YOUR_FQDN_OR_HOSTNAME {
reverse_proxy meshinfo:9000
}
handle_path /next/* {
rewrite * /next{uri}
reverse_proxy frontend:80
}
}
8 changes: 1 addition & 7 deletions Dockerfile.spa
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ RUN corepack enable
RUN yarn
RUN yarn build --base=/next/

FROM nginx:alpine

COPY --from=build /frontend/dist /usr/share/nginx/html/next

COPY frontend/nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
CMD ["/frontend/scripts/run-frontend.sh"]
3 changes: 1 addition & 2 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ services:
build:
context: .
dockerfile: Dockerfile.spa
volumes:
- ./frontend/dist:/usr/share/nginx/html/next
ports:
- 8000:80
environment:
- VITE_API_BASE_URL=/api
- NODE_ENV=production
restart: always

Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ services:
ports:
- 8000:80
environment:
- VITE_API_BASE_URL=/api
- NODE_ENV=production
restart: always

caddy:
image: caddy:latest
ports:
- 80:80
- 8443:443
- 443:443
volumes:
- ./caddy/data:/data/caddy
- ./Caddyfile:/etc/caddy/Caddyfile
Expand Down
8 changes: 8 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ dist-ssr
*.njsproj
*.sln
*.sw?

.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
Binary file removed frontend/.yarn/install-state.gz
Binary file not shown.
14 changes: 0 additions & 14 deletions frontend/nginx.conf

This file was deleted.

3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"autoprefixer": "^10.4.19",
"date-fns": "^3.6.0",
"date-fns-tz": "^3.1.3",
"express": "^4.19.2",
"ol": "^9.2.4",
"pm2": "^5.4.2",
"postcss": "^8.4.38",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -24,6 +26,7 @@
"tailwindcss": "^3.4.4"
},
"devDependencies": {
"@types/express": "^4",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.0.0",
Expand Down
2 changes: 2 additions & 0 deletions frontend/scripts/run-frontend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo "API BASE URL: " $VITE_API_BASE_URL
yarn build --base=/next/ && npx pm2-runtime /frontend/scripts/server.js
27 changes: 27 additions & 0 deletions frontend/scripts/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import express from "express";
import path, { dirname } from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const app = express();
const port = process.env.PORT || 80;

// Serve static files from the dist directory
app.use("/next", express.static(path.join(__dirname, "../dist")));

// log all requests
app.use((req, res, next) => {
console.log(req.method, req.url);
next();
});

// Handle every other route with index.html, which will contain a script tag to your application's JavaScript
app.get("/next/*", (req, res) => {
res.sendFile(path.join(__dirname, "../dist", "index.html"));
});

app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
Loading

0 comments on commit ae9282f

Please sign in to comment.