Skip to content

Commit c0cefe4

Browse files
chore: fix some small issue for deploy (#161)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Updated login flow: Email confirmation is now conditional, allowing sign-in when email functionality is disabled. - Introduced dynamic protocol handling for project previews and container deployments, enabling seamless HTTP/HTTPS transitions. - Added secure reverse proxy and TLS configurations to enhance connectivity and security. - **Chores** - Expanded configuration options for database and service settings. - Improved the build process with enhanced cleanup and modern networking adjustments. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent e256a9e commit c0cefe4

File tree

14 files changed

+441
-304
lines changed

14 files changed

+441
-304
lines changed

backend/src/auth/auth.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class AuthService {
4545
) {
4646
// Read the MAIL_ENABLED environment variable, default to 'true'
4747
this.isMailEnabled =
48-
this.configService.get<string>('MAIL_ENABLED', 'true').toLowerCase() ===
48+
this.configService.get<string>('MAIL_ENABLED', 'false').toLowerCase() ===
4949
'true';
5050
}
5151

@@ -192,7 +192,7 @@ export class AuthService {
192192
throw new UnauthorizedException('Invalid credentials');
193193
}
194194

195-
if (!user.isEmailConfirmed) {
195+
if (!user.isEmailConfirmed && this.isMailEnabled) {
196196
throw new Error('Email not confirmed. Please check your inbox.');
197197
}
198198

backend/src/config/env.validation.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
1-
import { IsOptional, IsString, IsNumber, IsIn } from 'class-validator';
1+
import { IsOptional, IsString, IsNumber, IsIn, IsPort } from 'class-validator';
22

33
export class EnvironmentVariables {
4+
// Database Configuration - all optional
5+
@IsOptional()
6+
@IsString()
7+
DB_HOST?: string;
8+
9+
@IsOptional()
10+
@IsPort()
11+
DB_PORT?: string;
12+
13+
@IsOptional()
14+
@IsString()
15+
DB_USERNAME?: string;
16+
17+
@IsOptional()
18+
@IsString()
19+
DB_PASSWORD?: string;
20+
21+
@IsOptional()
22+
@IsString()
23+
DB_DATABASE?: string;
24+
425
@IsNumber()
526
PORT: number;
627

backend/template/react-ts/vite.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ export default defineConfig({
3030
watch: {
3131
usePolling: true,
3232
},
33+
allowedHosts: true,
3334
},
3435
});

codefox-common/package.json

+1-10
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,11 @@
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.js",
77
"types": "dist/types/index.d.ts",
8-
"exports": {
9-
".": {
10-
"import": "./dist/esm/index.js",
11-
"require": "./dist/cjs/index.js",
12-
"types": "./dist/types/index.d.ts",
13-
"default": "./dist/esm/index.js"
14-
},
15-
"./dist/*": "./dist/*"
16-
},
178
"files": [
189
"dist"
1910
],
2011
"scripts": {
21-
"build": "pnpm run build:cjs && pnpm run build:esm && pnpm run build:types",
12+
"build": "rimraf dist && pnpm run build:cjs && pnpm run build:esm && pnpm run build:types",
2213
"build:frontend": "pnpm run build",
2314
"build:backend": "pnpm run build",
2415
"build:cjs": "tsc -p tsconfig.cjs.json",

docker/docker-compose.pord.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: '3'
2+
3+
services:
4+
reverse-proxy:
5+
image: traefik:v3.3
6+
command:
7+
- '--api.insecure=true'
8+
- '--providers.docker=true'
9+
- '--providers.docker.exposedbydefault=false'
10+
- '--providers.file.directory=/etc/traefik/config'
11+
- '--providers.file.watch=true'
12+
- '--entrypoints.web.address=:80'
13+
- '--entrypoints.websecure.address=:443'
14+
ports:
15+
- '80:80'
16+
- '443:443'
17+
- '9001:8080'
18+
volumes:
19+
- /var/run/docker.sock:/var/run/docker.sock
20+
- /etc/letsencrypt:/etc/letsencrypt
21+
- ./traefik-config:/etc/traefik/config
22+
networks:
23+
- traefik_network
24+
extra_hosts:
25+
- 'host.docker.internal:host-gateway'
26+
27+
networks:
28+
traefik_network:
29+
driver: bridge
File renamed without changes.

docker/traefik-config/services.yml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
http:
2+
routers:
3+
frontend:
4+
rule: 'Host(`codefox.net`) && !PathPrefix(`/graphql`)'
5+
entrypoints:
6+
- websecure
7+
tls: {}
8+
service: frontend
9+
priority: 10
10+
11+
backend:
12+
rule: 'Host(`codefox.net`) && PathPrefix(`/graphql`)'
13+
entrypoints:
14+
- websecure
15+
tls: {}
16+
service: backend
17+
priority: 20
18+
redirect-all:
19+
rule: 'hostregexp(`{host:.+}`)'
20+
entrypoints:
21+
- web
22+
middlewares:
23+
- redirect-to-https
24+
service: noop
25+
26+
services:
27+
frontend:
28+
loadBalancer:
29+
servers:
30+
- url: 'http://host.docker.internal:3000'
31+
32+
backend:
33+
loadBalancer:
34+
servers:
35+
- url: 'http://host.docker.internal:8080'
36+
37+
noop:
38+
loadBalancer:
39+
servers:
40+
- url: 'http://localhost:9000'
41+
42+
middlewares:
43+
redirect-to-https:
44+
redirectScheme:
45+
scheme: https
46+
permanent: true
47+
48+
cors:
49+
headers:
50+
accessControlAllowMethods:
51+
- GET
52+
- POST
53+
- PUT
54+
- DELETE
55+
- OPTIONS
56+
accessControlAllowHeaders:
57+
- Content-Type
58+
- Authorization

docker/traefik-config/tls.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
tls:
2+
certificates:
3+
- certFile: /etc/letsencrypt/live/codefox.net/fullchain.pem
4+
keyFile: /etc/letsencrypt/live/codefox.net/privkey.pem

frontend/.env.example

+5
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
NEXT_PUBLIC_GRAPHQL_URL=http://localhost:8080/graphql
2+
3+
# TLS OPTION for HTTPS
4+
TLS=false
5+
# TRAEFIK OPTION for HTTPS
6+
TRAEFIK_DOMAIN=your_domain.com

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

+20-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import puppetter from 'puppeteer';
77
import { useMutation } from '@apollo/client/react/hooks/useMutation';
88
import { toast } from 'sonner';
99
import { UPDATE_PROJECT_PHOTO_URL } from '@/graphql/request';
10+
import { TLS } from '@/utils/const';
1011

1112
const runningContainers = new Map<
1213
string,
@@ -147,12 +148,25 @@ async function buildAndRunDocker(
147148
console.log(`Running Docker container: ${containerName}`);
148149

149150
// 3. Run the Docker container
150-
const runCommand = `docker run -d --name ${containerName} -l "traefik.enable=true" \
151-
-l "traefik.http.routers.${subdomain}.rule=Host(\\"${domain}\\")" \
152-
-l "traefik.http.services.${subdomain}.loadbalancer.server.port=5173" \
153-
--network=codefox_traefik_network -p ${exposedPort}:5173 \
154-
-v "${directory}:/app" \
155-
${imageName}`;
151+
let runCommand;
152+
if (TLS) {
153+
runCommand = `docker run -d --name ${containerName} -l "traefik.enable=true" \
154+
-l "traefik.http.routers.${subdomain}.rule=Host(\\"${domain}\\")" \
155+
-l "traefik.http.routers.${subdomain}.entrypoints=websecure" \
156+
-l "traefik.http.routers.${subdomain}.tls=true" \
157+
-l "traefik.http.services.${subdomain}.loadbalancer.server.port=5173" \
158+
--network=codefox_traefik_network -p ${exposedPort}:5173 \
159+
-v "${directory}:/app" \
160+
${imageName}`;
161+
} else {
162+
runCommand = `docker run -d --name ${containerName} -l "traefik.enable=true" \
163+
-l "traefik.http.routers.${subdomain}.rule=Host(\\"${domain}\\")" \
164+
-l "traefik.http.routers.${subdomain}.entrypoints=web" \
165+
-l "traefik.http.services.${subdomain}.loadbalancer.server.port=5173" \
166+
--network=codefox_traefik_network -p ${exposedPort}:5173 \
167+
-v "${directory}:/app" \
168+
${imageName}`;
169+
}
156170

157171
console.log(`Executing run command: ${runCommand}`);
158172

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ZoomOut,
1313
} from 'lucide-react';
1414
import puppeteer from 'puppeteer';
15+
import { URL_PROTOCOL_PREFIX } from '@/utils/const';
1516

1617
export default function WebPreview() {
1718
const { curProject, getWebUrl } = useContext(ProjectContext);
@@ -41,7 +42,7 @@ export default function WebPreview() {
4142
lastProjectPathRef.current = projectPath;
4243

4344
if (containerRef.current?.projectPath === projectPath) {
44-
setBaseUrl(`http://${containerRef.current.domain}`);
45+
setBaseUrl(`${URL_PROTOCOL_PREFIX}://${containerRef.current.domain}`);
4546
return;
4647
}
4748

@@ -52,7 +53,7 @@ export default function WebPreview() {
5253
domain,
5354
};
5455

55-
const baseUrl = `http://${domain}`;
56+
const baseUrl = `${URL_PROTOCOL_PREFIX}://${domain}`;
5657
console.log('baseUrl:', baseUrl);
5758
setBaseUrl(baseUrl);
5859
setDisplayPath('/');

frontend/src/components/root/expand-card.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React, { useContext, useEffect, useRef, useState } from 'react';
44
import { AnimatePresence, motion } from 'framer-motion';
55
import { X } from 'lucide-react';
66
import { ProjectContext } from '../chat/code-engine/project-context';
7+
import { URL_PROTOCOL_PREFIX } from '@/utils/const';
78

89
export function ExpandableCard({ projects }) {
910
const [active, setActive] = useState(null);
@@ -37,7 +38,7 @@ export function ExpandableCard({ projects }) {
3738

3839
try {
3940
const data = await getWebUrl(project.path);
40-
const url = `http://${data.domain}`;
41+
const url = `${URL_PROTOCOL_PREFIX}://${data.domain}`;
4142
cachedUrls.current.set(project.id, url);
4243
setIframeUrl(url);
4344
} catch (error) {
@@ -120,7 +121,7 @@ export function ExpandableCard({ projects }) {
120121
const data = await getWebUrl(project.path);
121122

122123
console.log(project.image);
123-
const url = `http://${data.domain}`;
124+
const url = `${URL_PROTOCOL_PREFIX}://${data.domain}`;
124125
setIframeUrl(url);
125126
handleCardClick(project);
126127
setActive(project);

frontend/src/utils/const.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @description: API URL
3+
* @type {string}
4+
* @example 'https://api.example.com'
5+
*/
6+
export const URL_PROTOCOL_PREFIX =
7+
process.env.TLS == 'false' ? 'http' : 'https';
8+
9+
/**
10+
* Validate if the current environment is using TLS
11+
*/
12+
export const TLS = process.env.TLS == 'true';

0 commit comments

Comments
 (0)