Add reverse proxy to docker compose (traefik)
This commit is contained in:
parent
65aaa33f4f
commit
28b2988b86
@ -1,6 +1,21 @@
|
||||
version: "3.7"
|
||||
|
||||
services:
|
||||
# Reverse proxy
|
||||
traefik:
|
||||
image: "traefik:v2.8"
|
||||
command:
|
||||
#- "--log.level=DEBUG"
|
||||
- "--api.insecure=true" # allows accessing a Traefik dashboard, disable in production
|
||||
- "--providers.docker=true" # enables the Docker configuration discovery
|
||||
- "--providers.docker.exposedbydefault=false" # do not expose Docker services by default
|
||||
- "--entrypoints.web.address=:5000" # create an entrypoint called web, listening on :5000
|
||||
ports:
|
||||
- "5000:5000"
|
||||
- "8765:8080"
|
||||
volumes:
|
||||
- "/var/run/docker.sock:/var/run/docker.sock:ro"
|
||||
|
||||
# Prisma sqlite migration utility
|
||||
migrate:
|
||||
build:
|
||||
@ -16,32 +31,36 @@ services:
|
||||
build:
|
||||
context: ./server
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- sqlite:/database/
|
||||
environment:
|
||||
- DATABASE_URL=file:/database/db.sqlite
|
||||
- FRONTEND_URL=http://localhost:3000
|
||||
- FRONTEND_URL=http://localhost:5000
|
||||
- CLEANUP_INTERVAL_SECONDS=600
|
||||
- POST_LIMIT_WINDOW_SECONDS=86400
|
||||
- POST_LIMIT=50
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
|
||||
labels:
|
||||
- "traefik.enable=true" # tell Traefik this is something we would like to expose
|
||||
- "traefik.http.routers.backend.entrypoints=web" # what entrypoint should be used for the backend service.
|
||||
- "traefik.http.routers.backend.rule=Host(`localhost`) && PathPrefix(`/api`) && Method(`POST`)" #
|
||||
|
||||
# Frontend for serving encrypted notes over HTML (SvelteKit)
|
||||
frontend:
|
||||
build:
|
||||
context: ./webapp
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
- VITE_SERVER_INTERNAL=http://server:8080
|
||||
- VITE_SERVER_INTERNAL=http://backend:8080
|
||||
- VITE_BRANDING=Noteshare.space [preview]
|
||||
ports:
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
- backend
|
||||
labels:
|
||||
- "traefik.enable=true" # tell Traefik this is something we would like to expose
|
||||
- "traefik.http.routers.frontend.entrypoints=web" # what entrypoint should be used for the frontend service.
|
||||
- "traefik.http.routers.frontend.rule=Host(`localhost`)" #
|
||||
|
||||
volumes:
|
||||
sqlite:
|
@ -32,7 +32,7 @@ export class NoteSharingService {
|
||||
hmac: string
|
||||
): Promise<Response> {
|
||||
const res = await requestUrl({
|
||||
url: `${this._url}/note`,
|
||||
url: `${this._url}/api/note`,
|
||||
method: "POST",
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({ ciphertext, hmac }),
|
||||
|
@ -34,7 +34,7 @@ app.listen(process.env.PORT, () => {
|
||||
|
||||
// Post new encrypted note
|
||||
app.post(
|
||||
"/note/",
|
||||
"/api/note/",
|
||||
postLimiter,
|
||||
async (req: Request<{}, {}, EncryptedNote>, res) => {
|
||||
const note = req.body;
|
||||
@ -49,7 +49,7 @@ app.post(
|
||||
);
|
||||
|
||||
// Get encrypted note
|
||||
app.get("/note/:id", async (req, res) => {
|
||||
app.get("/api/note/:id", async (req, res) => {
|
||||
const note = await prisma.encryptedNote.findUnique({
|
||||
where: { id: req.params.id },
|
||||
});
|
||||
@ -62,7 +62,8 @@ app.get("/note/:id", async (req, res) => {
|
||||
|
||||
// Default response for any other request
|
||||
app.use((req, res, next) => {
|
||||
res.status(404).send();
|
||||
console.log(`Route not found: ${req.path}`);
|
||||
res.status(404).send("Route not found");
|
||||
});
|
||||
|
||||
// // Error handling
|
||||
|
@ -2,7 +2,7 @@ import type { EncryptedNote } from '$lib/model/EncryptedNote';
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
|
||||
export const get: RequestHandler = async ({ params }) => {
|
||||
const url = `${import.meta.env.VITE_SERVER_INTERNAL}/note/${params.id}`;
|
||||
const url = `${import.meta.env.VITE_SERVER_INTERNAL}/api/note/${params.id}`;
|
||||
const response = await fetch(url);
|
||||
|
||||
if (response.ok) {
|
||||
|
Loading…
Reference in New Issue
Block a user