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

chore: add development reverse proxy #39

Merged
merged 10 commits into from
Aug 10, 2023
10 changes: 7 additions & 3 deletions .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ services:
- type: bind
source: ../strapi
target: /app
ports:
# Expose strapi to port 8001
- "8001:8001"
depends_on:
- strapi-postgres

Expand Down Expand Up @@ -62,6 +59,13 @@ services:
source: ../app
target: /app

caddy:
image: caddy
volumes:
- "../caddy/Caddyfile.dev:/etc/caddy/Caddyfile"
ports:
- "80:80"

volumes:
# Persist strapi database
strapi-data:
19 changes: 10 additions & 9 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions caddy/Caddyfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
auto_https off
}

http://localhost:80 {
handle_path /strapi* {
reverse_proxy http://strapi:8001
}

reverse_proxy http://app:3000
}
1 change: 1 addition & 0 deletions strapi/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
HOST=0.0.0.0
PORT=8001
URL=http://localhost/strapi
APP_KEYS="toBeModified1,toBeModified2"
API_TOKEN_SALT=tobemodified
ADMIN_JWT_SECRET=tobemodified
Expand Down
1 change: 1 addition & 0 deletions strapi/config/middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export default [
"strapi::session",
"strapi::favicon",
"strapi::public",
{ resolve: "./src/middlewares/admin-redirect" },
];
1 change: 1 addition & 0 deletions strapi/config/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export default ({ env }) => ({
app: {
keys: env.array("APP_KEYS"),
},
url: env("URL", "http://localhost/strapi"),
});
15 changes: 15 additions & 0 deletions strapi/src/middlewares/admin-redirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* `admin-redirect` middleware
*/
import { Strapi } from "@strapi/strapi";

export default (config, { strapi }: { strapi: Strapi }) => {
const redirects = ["/", "/index.html"].map((path) => ({
method: "GET",
path,
handler: (ctx) => ctx.redirect(strapi.config.admin.url),
config: { auth: false },
}));

strapi.server.routes(redirects);
};