Skip to content

Commit 4e0987d

Browse files
Sma1lboyautofix-ci[bot]ZHallen122
authored
chore: fix some small issue for deploy (#164)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced email confirmation logic that now considers mail service settings. - Expanded configuration options with database parameters, TLS support, and reverse proxy routing for improved security and flexibility. - **Refactor** - Improved frontend components with dynamic URL protocol handling. - Streamlined container deployment commands and module imports for cleaner builds. - **Chores** - Optimized build scripts and configuration files to ensure efficient deployments. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: ZHallen122 <106571949+ZHallen122@users.noreply.github.com>
1 parent 0ff5937 commit 4e0987d

File tree

5 files changed

+53
-11
lines changed

5 files changed

+53
-11
lines changed

docker/traefik-config/services.yml

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ http:
1515
tls: {}
1616
service: backend
1717
priority: 20
18+
19+
subdomain:
20+
rule: 'HostRegexp(`{subdomain:.+}.codefox.net`)'
21+
entrypoints:
22+
- websecure
23+
tls: {}
24+
service: frontend
25+
priority: 30
26+
1827
redirect-all:
1928
rule: 'hostregexp(`{host:.+}`)'
2029
entrypoints:

frontend/src/app/api/runProject/route.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ async function buildAndRunDocker(
155155
-l "traefik.http.routers.${subdomain}.entrypoints=websecure" \
156156
-l "traefik.http.routers.${subdomain}.tls=true" \
157157
-l "traefik.http.services.${subdomain}.loadbalancer.server.port=5173" \
158-
--network=codefox_traefik_network -p ${exposedPort}:5173 \
158+
--network=docker_traefik_network -p ${exposedPort}:5173 \
159159
-v "${directory}:/app" \
160160
${imageName}`;
161161
} else {
162162
runCommand = `docker run -d --name ${containerName} -l "traefik.enable=true" \
163163
-l "traefik.http.routers.${subdomain}.rule=Host(\\"${domain}\\")" \
164164
-l "traefik.http.routers.${subdomain}.entrypoints=web" \
165165
-l "traefik.http.services.${subdomain}.loadbalancer.server.port=5173" \
166-
--network=codefox_traefik_network -p ${exposedPort}:5173 \
166+
--network=docker_traefik_network -p ${exposedPort}:5173 \
167167
-v "${directory}:/app" \
168168
${imageName}`;
169169
}

frontend/src/components/chat/code-engine/project-context.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { Project } from '../project-modal';
2020
import { useRouter } from 'next/navigation';
2121
import { toast } from 'sonner'; // Assuming you use Sonner for toasts
2222
import { useAuthContext } from '@/providers/AuthProvider';
23+
import { URL_PROTOCOL_PREFIX } from '@/utils/const';
2324

2425
export interface ProjectContextType {
2526
projects: Project[];
@@ -277,7 +278,7 @@ export function ProjectProvider({ children }: { children: ReactNode }) {
277278
}
278279

279280
const data = await response.json();
280-
const baseUrl = `http://${data.domain}`;
281+
const baseUrl = `${URL_PROTOCOL_PREFIX}://${data.domain}`;
281282
const project = projects.find((p) => p.projectPath === projectPath);
282283
if (project) {
283284
await takeProjectScreenshot(project.id, baseUrl);
@@ -439,7 +440,7 @@ export function ProjectProvider({ children }: { children: ReactNode }) {
439440

440441
if (response.ok) {
441442
const data = await response.json();
442-
const baseUrl = `http://${data.domain}`;
443+
const baseUrl = `${URL_PROTOCOL_PREFIX}://${data.domain}`;
443444
await takeProjectScreenshot(project.id, baseUrl);
444445
}
445446
} catch (error) {

frontend/src/components/chat/code-engine/web-view.tsx

+27-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import {
1414
import puppeteer from 'puppeteer';
1515
import { URL_PROTOCOL_PREFIX } from '@/utils/const';
1616

17-
export default function WebPreview() {
18-
const { curProject, getWebUrl } = useContext(ProjectContext);
19-
if (!curProject || !getWebUrl) {
20-
throw new Error('ProjectContext not properly initialized');
21-
}
17+
function PreviewContent({
18+
curProject,
19+
getWebUrl,
20+
}: {
21+
curProject: any;
22+
getWebUrl: any;
23+
}) {
2224
const [baseUrl, setBaseUrl] = useState('');
2325
const [displayPath, setDisplayPath] = useState('/');
2426
const [history, setHistory] = useState<string[]>(['/']);
@@ -109,6 +111,7 @@ export default function WebPreview() {
109111
setDisplayPath(history[currentIndex + 1]);
110112
}
111113
};
114+
112115
const reloadIframe = () => {
113116
const iframe = document.getElementById('myIframe') as HTMLIFrameElement;
114117
if (iframe) {
@@ -241,3 +244,22 @@ export default function WebPreview() {
241244
</div>
242245
);
243246
}
247+
248+
export default function WebPreview() {
249+
const context = useContext(ProjectContext);
250+
251+
if (!context) {
252+
return (
253+
<div className="flex items-center justify-center h-full">
254+
<p className="text-sm text-muted-foreground">Loading project...</p>
255+
</div>
256+
);
257+
}
258+
259+
return (
260+
<PreviewContent
261+
curProject={context.curProject}
262+
getWebUrl={context.getWebUrl}
263+
/>
264+
);
265+
}

frontend/src/utils/const.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33
* @type {string}
44
* @example 'https://api.example.com'
55
*/
6+
/**
7+
* Always use HTTPS when the page is loaded over HTTPS
8+
*/
69
export const URL_PROTOCOL_PREFIX =
7-
process.env.TLS == 'false' ? 'http' : 'https';
10+
typeof window !== 'undefined' && window.location.protocol === 'https:'
11+
? 'https'
12+
: process.env.TLS == 'false'
13+
? 'http'
14+
: 'https';
815

916
/**
1017
* Validate if the current environment is using TLS
1118
*/
12-
export const TLS = process.env.TLS == 'true';
19+
export const TLS =
20+
typeof window !== 'undefined' && window.location.protocol === 'https:'
21+
? true
22+
: process.env.TLS == 'true';

0 commit comments

Comments
 (0)