Skip to content

Commit 5719db7

Browse files
committed
feat: url test
1 parent 5967608 commit 5719db7

File tree

6 files changed

+62
-16
lines changed

6 files changed

+62
-16
lines changed

Dockerfile

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1-
FROM node:latest AS builder
1+
# Build stage
2+
FROM --platform=linux/amd64 node:21-alpine AS build
23
WORKDIR /app
3-
COPY package*.json ./
4-
RUN npm ci
4+
COPY package.json package-lock.json ./
5+
RUN npm ci --ignore-scripts --include=dev
56
COPY . .
6-
RUN git submodule update --init
7-
RUN npm run build
8-
EXPOSE 8000
9-
CMD ["npm", "run", "dev"]
7+
RUN npm run build:prod
8+
RUN ls -l /app/dist && cat /app/dist/index.html # Debug build output
9+
10+
# Production stage
11+
FROM --platform=linux/amd64 node:21-alpine AS production
12+
WORKDIR /app
13+
ENV NODE_ENV=production
14+
RUN npm install -g --only=production http-server
15+
COPY --from=build /app/dist ./dist
16+
# Inject script tag
17+
RUN sed -i '/<head>/ s|<head>|<head>\n <script src="/config.js"></script>|' /app/dist/index.html && \
18+
cat /app/dist/index.html # Debug sed output
19+
# Create entrypoint script to inject config.js at runtime
20+
RUN echo '#!/bin/sh' > /app/entrypoint.sh && \
21+
echo 'if [ -z "$VITE_HOST_URL" ]; then' >> /app/entrypoint.sh && \
22+
echo ' echo "window.appConfig = { apiBaseUrl: \"\" };" > /app/dist/config.js' >> /app/entrypoint.sh && \
23+
echo 'else' >> /app/entrypoint.sh && \
24+
echo ' echo "window.appConfig = { apiBaseUrl: \"$VITE_HOST_URL\" };" > /app/dist/config.js' >> /app/entrypoint.sh && \
25+
echo 'fi' >> /app/entrypoint.sh && \
26+
echo 'cat /app/dist/config.js' >> /app/entrypoint.sh && \
27+
echo 'exec http-server ./dist -p 80 --spa' >> /app/entrypoint.sh && \
28+
chmod +x /app/entrypoint.sh
29+
EXPOSE 80
30+
ENTRYPOINT ["/app/entrypoint.sh"]

index.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<!doctype html>
22
<html lang="en">
33
<head>
4-
<% if (env.VITE_GTM_ID) { %>
54
<!-- Google Tag Manager -->
65
<script>
76
(function (w, d, s, l, i) {
@@ -16,7 +15,6 @@
1615
})(window, document, "script", "dataLayer", "<%= env.VITE_GTM_ID %>");
1716
</script>
1817
<!-- End Google Tag Manager -->
19-
<% } %>
2018

2119
<meta charset="UTF-8" />
2220
<link rel="icon" type="image/svg+xml" href="/favicon.png" />
@@ -38,7 +36,7 @@
3836
<!-- Google Tag Manager (noscript) -->
3937
<noscript
4038
><iframe
41-
src="https://www.googletagmanager.com/ns.html?id=%VITE_GTM_ID%"
39+
src="https://www.googletagmanager.com/ns.html?id=<%= env.VITE_GTM_ID %>"
4240
height="0"
4341
width="0"
4442
style="display: none; visibility: hidden"
@@ -60,4 +58,4 @@
6058
<!-- End of HubSpot Embed Code -->
6159
<% } %>
6260
</body>
63-
</html>
61+
</html>

src/assets/templates/kittehub.zip

80 KB
Binary file not shown.

src/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface AppConfig {
2+
apiBaseUrl: string;
3+
}
4+
5+
const runtimeConfig = (window as any).appConfig || {};
6+
export const config: AppConfig = {
7+
apiBaseUrl: runtimeConfig.apiBaseUrl || "",
8+
};

src/utilities/getApiBaseUrl.utils.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
1+
import { config } from "@src/config";
2+
13
export const getApiBaseUrl = (): string => {
4+
const buildUrl = (url: string): string => {
5+
if (url.match(/^(http|https):\/\//)) {
6+
return url;
7+
} else {
8+
const path = url.startsWith("/") ? url.substring(1) : url;
9+
return `${window.location.origin}/${path}`;
10+
}
11+
};
12+
13+
if (config?.apiBaseUrl) {
14+
return buildUrl(config.apiBaseUrl);
15+
}
16+
17+
const hostUrl = import.meta.env.VITE_HOST_URL;
18+
if (hostUrl) {
19+
return buildUrl(hostUrl);
20+
}
221
const { hostname } = window.location;
22+
323
if (hostname === "app.autokitteh.cloud") {
424
return "https://api.autokitteh.cloud";
525
}
26+
627
if (hostname.endsWith(".autokitteh.cloud")) {
728
const [env, ...rest] = hostname.split(".");
8-
929
return `https://${env}-api.${rest.join(".")}`;
1030
}
1131

12-
return import.meta.env.VITE_HOST_URL || "http://localhost:9980";
32+
return "http://localhost:9980";
1333
};

vite.config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ export default defineConfig({
153153
},
154154

155155
server: {
156-
host: process.env.VITE_APP_DOMAIN ? JSON.stringify(process.env.VITE_APP_DOMAIN) : true,
157-
port: process.env.VITE_LOCAL_PORT ? Number(process.env.VITE_LOCAL_PORT) : 8000,
158-
strictPort: true,
156+
port: 8000,
157+
allowedHosts: true,
159158
},
160159
});

0 commit comments

Comments
 (0)