Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
) {
// Read the MAIL_ENABLED environment variable, default to 'true'
this.isMailEnabled =
this.configService.get<string>('MAIL_ENABLED', 'true').toLowerCase() ===
this.configService.get<string>('MAIL_ENABLED', 'false').toLowerCase() ===
'true';
}

Expand Down Expand Up @@ -80,7 +80,7 @@
message: 'Email already confirmed or user not found.',
success: false,
};
} catch (error) {

Check warning on line 83 in backend/src/auth/auth.service.ts

View workflow job for this annotation

GitHub Actions / autofix

'error' is defined but never used
return {
message: 'Invalid or expired token',
success: false,
Expand Down Expand Up @@ -192,7 +192,7 @@
throw new UnauthorizedException('Invalid credentials');
}

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

Expand Down Expand Up @@ -252,7 +252,7 @@
}

return true;
} catch (error) {

Check warning on line 255 in backend/src/auth/auth.service.ts

View workflow job for this annotation

GitHub Actions / autofix

'error' is defined but never used
return false;
}
}
Expand Down
25 changes: 23 additions & 2 deletions backend/src/config/env.validation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import { IsOptional, IsString, IsNumber, IsIn } from 'class-validator';
import { IsOptional, IsString, IsNumber, IsIn, IsPort } from 'class-validator';

export class EnvironmentVariables {
// Database Configuration - all optional
@IsOptional()
@IsString()
DB_HOST?: string;

@IsOptional()
@IsPort()
DB_PORT?: string;

@IsOptional()
@IsString()
DB_USERNAME?: string;

@IsOptional()
@IsString()
DB_PASSWORD?: string;

@IsOptional()
@IsString()
DB_DATABASE?: string;

@IsNumber()
PORT: number;
PORT: number = 8000;

@IsString()
@IsIn(['DEV', 'PROD', 'TEST'])
Expand Down
1 change: 1 addition & 0 deletions backend/template/react-ts/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ export default defineConfig({
watch: {
usePolling: true,
},
allowedHosts: true,
},
});
11 changes: 1 addition & 10 deletions codefox-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,11 @@
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"types": "./dist/types/index.d.ts",
"default": "./dist/esm/index.js"
},
"./dist/*": "./dist/*"
},
"files": [
"dist"
],
"scripts": {
"build": "pnpm run build:cjs && pnpm run build:esm && pnpm run build:types",
"build": "rimraf dist && pnpm run build:cjs && pnpm run build:esm && pnpm run build:types",
"build:frontend": "pnpm run build",
"build:backend": "pnpm run build",
"build:cjs": "tsc -p tsconfig.cjs.json",
Expand Down
29 changes: 29 additions & 0 deletions docker/docker-compose.pord.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3'

services:
reverse-proxy:
image: traefik:v3.3
command:
- '--api.insecure=true'
- '--providers.docker=true'
- '--providers.docker.exposedbydefault=false'
- '--providers.file.directory=/etc/traefik/config'
- '--providers.file.watch=true'
- '--entrypoints.web.address=:80'
- '--entrypoints.websecure.address=:443'
ports:
- '80:80'
- '443:443'
- '9001:8080'
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /etc/letsencrypt:/etc/letsencrypt
- ./traefik-config:/etc/traefik/config
networks:
- traefik_network
extra_hosts:
- 'host.docker.internal:host-gateway'

networks:
traefik_network:
driver: bridge
File renamed without changes.
58 changes: 58 additions & 0 deletions docker/traefik-config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
http:
routers:
frontend:
rule: 'Host(`codefox.net`) && !PathPrefix(`/graphql`)'
entrypoints:
- websecure
tls: {}
service: frontend
priority: 10

backend:
rule: 'Host(`codefox.net`) && PathPrefix(`/graphql`)'
entrypoints:
- websecure
tls: {}
service: backend
priority: 20
redirect-all:
rule: 'hostregexp(`{host:.+}`)'
entrypoints:
- web
middlewares:
- redirect-to-https
service: noop

services:
frontend:
loadBalancer:
servers:
- url: 'http://host.docker.internal:3000'

backend:
loadBalancer:
servers:
- url: 'http://host.docker.internal:8080'

noop:
loadBalancer:
servers:
- url: 'http://localhost:9000'

middlewares:
redirect-to-https:
redirectScheme:
scheme: https
permanent: true

cors:
headers:
accessControlAllowMethods:
- GET
- POST
- PUT
- DELETE
- OPTIONS
accessControlAllowHeaders:
- Content-Type
- Authorization
4 changes: 4 additions & 0 deletions docker/traefik-config/tls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tls:
certificates:
- certFile: /etc/letsencrypt/live/codefox.net/fullchain.pem
keyFile: /etc/letsencrypt/live/codefox.net/privkey.pem
5 changes: 5 additions & 0 deletions frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
NEXT_PUBLIC_GRAPHQL_URL=http://localhost:8080/graphql

# TLS OPTION for HTTPS
TLS=false
# TRAEFIK OPTION for HTTPS
TRAEFIK_DOMAIN=your_domain.com
26 changes: 20 additions & 6 deletions frontend/src/app/api/runProject/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import puppetter from 'puppeteer';
import { useMutation } from '@apollo/client/react/hooks/useMutation';
import { toast } from 'sonner';
import { UPDATE_PROJECT_PHOTO_URL } from '@/graphql/request';
import { TLS } from '@/utils/const';

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

// 3. Run the Docker container
const runCommand = `docker run -d --name ${containerName} -l "traefik.enable=true" \
-l "traefik.http.routers.${subdomain}.rule=Host(\\"${domain}\\")" \
-l "traefik.http.services.${subdomain}.loadbalancer.server.port=5173" \
--network=codefox_traefik_network -p ${exposedPort}:5173 \
-v "${directory}:/app" \
${imageName}`;
let runCommand;
if (TLS) {
runCommand = `docker run -d --name ${containerName} -l "traefik.enable=true" \
-l "traefik.http.routers.${subdomain}.rule=Host(\\"${domain}\\")" \
-l "traefik.http.routers.${subdomain}.entrypoints=websecure" \
-l "traefik.http.routers.${subdomain}.tls=true" \
-l "traefik.http.services.${subdomain}.loadbalancer.server.port=5173" \
--network=codefox_traefik_network -p ${exposedPort}:5173 \
-v "${directory}:/app" \
${imageName}`;
} else {
runCommand = `docker run -d --name ${containerName} -l "traefik.enable=true" \
-l "traefik.http.routers.${subdomain}.rule=Host(\\"${domain}\\")" \
-l "traefik.http.routers.${subdomain}.entrypoints=web" \
-l "traefik.http.services.${subdomain}.loadbalancer.server.port=5173" \
--network=codefox_traefik_network -p ${exposedPort}:5173 \
-v "${directory}:/app" \
${imageName}`;
}

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

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/chat/code-engine/web-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ZoomOut,
} from 'lucide-react';
import puppeteer from 'puppeteer';
import { URL_PROTOCOL_PREFIX } from '@/utils/const';

export default function WebPreview() {
const { curProject, getWebUrl } = useContext(ProjectContext);
Expand Down Expand Up @@ -41,7 +42,7 @@ export default function WebPreview() {
lastProjectPathRef.current = projectPath;

if (containerRef.current?.projectPath === projectPath) {
setBaseUrl(`http://${containerRef.current.domain}`);
setBaseUrl(`${URL_PROTOCOL_PREFIX}://${containerRef.current.domain}`);
return;
}

Expand All @@ -52,7 +53,7 @@ export default function WebPreview() {
domain,
};

const baseUrl = `http://${domain}`;
const baseUrl = `${URL_PROTOCOL_PREFIX}://${domain}`;
console.log('baseUrl:', baseUrl);
setBaseUrl(baseUrl);
setDisplayPath('/');
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/root/expand-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { useContext, useEffect, useRef, useState } from 'react';
import { AnimatePresence, motion } from 'framer-motion';
import { X } from 'lucide-react';
import { ProjectContext } from '../chat/code-engine/project-context';
import { URL_PROTOCOL_PREFIX } from '@/utils/const';

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

try {
const data = await getWebUrl(project.path);
const url = `http://${data.domain}`;
const url = `${URL_PROTOCOL_PREFIX}://${data.domain}`;
cachedUrls.current.set(project.id, url);
setIframeUrl(url);
} catch (error) {
Expand Down Expand Up @@ -120,7 +121,7 @@ export function ExpandableCard({ projects }) {
const data = await getWebUrl(project.path);

console.log(project.image);
const url = `http://${data.domain}`;
const url = `${URL_PROTOCOL_PREFIX}://${data.domain}`;
setIframeUrl(url);
handleCardClick(project);
setActive(project);
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/utils/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @description: API URL
* @type {string}
* @example 'https://api.example.com'
*/
export const URL_PROTOCOL_PREFIX =
process.env.TLS == 'false' ? 'http' : 'https';

/**
* Validate if the current environment is using TLS
*/
export const TLS = process.env.TLS == 'true';
2 changes: 1 addition & 1 deletion llm-server/src/downloader/model-downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Logger } from '@nestjs/common';
import { PipelineType, pipeline, env } from '@huggingface/transformers';
import { isRemoteModel } from './const';
import { UniversalStatusManager } from './universal-status';
import { getModelsDir } from 'codefox-common/dist/esm';
import { getModelsDir } from 'codefox-common';

env.allowLocalModels = true;
env.localModelPath = getModelsDir();
Expand Down
2 changes: 1 addition & 1 deletion llm-server/src/downloader/universal-status.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getModelStatusPath } from 'codefox-common/dist/esm';
import { getModelStatusPath } from 'codefox-common';
import * as fs from 'fs';
import * as path from 'path';

Expand Down
2 changes: 1 addition & 1 deletion llm-server/src/downloader/universal-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UniversalDownloader } from './model-downloader';
import { Logger } from '@nestjs/common';
import { UniversalStatusManager } from './universal-status';
import { ConfigLoader, getModelsDir } from 'codefox-common/dist/esm';
import { ConfigLoader, getModelsDir } from 'codefox-common';

const logger = new Logger('model-utils');

Expand Down
6 changes: 1 addition & 5 deletions llm-server/src/llm-provider.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Response } from 'express';
import { Logger } from '@nestjs/common';
import {
ConfigLoader,
ModelConfig,
ModelApiStreamChunk,
} from 'codefox-common/dist/esm';
import { ConfigLoader, ModelConfig, ModelApiStreamChunk } from 'codefox-common';
import {
ModelProviderType,
ModelProviderOptions,
Expand Down
5 changes: 2 additions & 3 deletions llm-server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist",
"rootDir": "./src",
"sourceMap": true,
"inlineSourceMap": false,
"inlineSources": true,
Expand All @@ -16,9 +17,7 @@
"resolveJsonModule": true,
"baseUrl": ".",
"paths": {
"*": ["node_modules/*"],
"codefox-common": ["../codefox-common/src"],
"codefox-common/*": ["../codefox-common/src/*"]
"*": ["node_modules/*"]
},
"types": ["node", "express"]
},
Expand Down
Loading
Loading