Skip to content

Commit

Permalink
fix: BASE_PATH by using caddy as web server.
Browse files Browse the repository at this point in the history
vite config use experimental renderBuiltUrl.
  • Loading branch information
riccox committed Dec 30, 2024
1 parent d3e0af4 commit 48e6b23
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 32 deletions.
26 changes: 26 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
# disable HTTPS
auto_https off
}

:24900 {
# CORS
header {
Access-Control-Allow-Headers *
Access-Control-Allow-Credentials true
Access-Control-Allow-Methods *
Access-Control-Allow-Origin *
defer
}
@options {
method OPTIONS
}
respond @options 204

# Base path
handle {$BASE_PATH:/}* {
uri strip_prefix {$BASE_PATH:/}
root * /srv
file_server
}
}
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ RUN pnpm install
RUN npm run build

# -------
FROM nginx
FROM caddy:2-alpine

COPY --from=build /opt/meilisearch-ui/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /opt/meilisearch-ui/dist /srv
COPY Caddyfile /etc/caddy/Caddyfile

EXPOSE 24900

CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
29 changes: 0 additions & 29 deletions nginx.conf

This file was deleted.

13 changes: 13 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,18 @@ export default defineConfig(({ mode }) => {
},
},
},
experimental: {
renderBuiltUrl(filename, { hostId, type }) {
if (type === "public") {
return `./${filename}`;
}
if (path.extname(hostId) === ".js") {
return {
runtime: `window.__assetsPath(${JSON.stringify(filename)})`,
};
}
return `./${filename}`;
},
},
};
});

0 comments on commit 48e6b23

Please sign in to comment.