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
9 changes: 9 additions & 0 deletions docker/traefik-config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ http:
tls: {}
service: backend
priority: 20

subdomain:
rule: 'HostRegexp(`{subdomain:.+}.codefox.net`)'
entrypoints:
- websecure
tls: {}
service: frontend
priority: 30

redirect-all:
rule: 'hostregexp(`{host:.+}`)'
entrypoints:
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/api/runProject/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ async function buildAndRunDocker(
-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 \
--network=docker_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 \
--network=docker_traefik_network -p ${exposedPort}:5173 \
-v "${directory}:/app" \
${imageName}`;
}
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/chat/code-engine/project-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Project } from '../project-modal';
import { useRouter } from 'next/navigation';
import { toast } from 'sonner'; // Assuming you use Sonner for toasts
import { useAuthContext } from '@/providers/AuthProvider';
import { URL_PROTOCOL_PREFIX } from '@/utils/const';

export interface ProjectContextType {
projects: Project[];
Expand Down Expand Up @@ -277,7 +278,7 @@ export function ProjectProvider({ children }: { children: ReactNode }) {
}

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

if (response.ok) {
const data = await response.json();
const baseUrl = `http://${data.domain}`;
const baseUrl = `${URL_PROTOCOL_PREFIX}://${data.domain}`;
await takeProjectScreenshot(project.id, baseUrl);
}
} catch (error) {
Expand Down
32 changes: 27 additions & 5 deletions frontend/src/components/chat/code-engine/web-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import {
import puppeteer from 'puppeteer';
import { URL_PROTOCOL_PREFIX } from '@/utils/const';

export default function WebPreview() {
const { curProject, getWebUrl } = useContext(ProjectContext);
if (!curProject || !getWebUrl) {
throw new Error('ProjectContext not properly initialized');
}
function PreviewContent({
curProject,
getWebUrl,
}: {
curProject: any;
getWebUrl: any;
}) {
const [baseUrl, setBaseUrl] = useState('');
const [displayPath, setDisplayPath] = useState('/');
const [history, setHistory] = useState<string[]>(['/']);
Expand Down Expand Up @@ -109,6 +111,7 @@ export default function WebPreview() {
setDisplayPath(history[currentIndex + 1]);
}
};

const reloadIframe = () => {
const iframe = document.getElementById('myIframe') as HTMLIFrameElement;
if (iframe) {
Expand Down Expand Up @@ -241,3 +244,22 @@ export default function WebPreview() {
</div>
);
}

export default function WebPreview() {
const context = useContext(ProjectContext);

if (!context) {
return (
<div className="flex items-center justify-center h-full">
<p className="text-sm text-muted-foreground">Loading project...</p>
</div>
);
}

return (
<PreviewContent
curProject={context.curProject}
getWebUrl={context.getWebUrl}
/>
);
}
14 changes: 12 additions & 2 deletions frontend/src/utils/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@
* @type {string}
* @example 'https://api.example.com'
*/
/**
* Always use HTTPS when the page is loaded over HTTPS
*/
export const URL_PROTOCOL_PREFIX =
process.env.TLS == 'false' ? 'http' : 'https';
typeof window !== 'undefined' && window.location.protocol === 'https:'
? 'https'
: process.env.TLS == 'false'
? 'http'
: 'https';

/**
* Validate if the current environment is using TLS
*/
export const TLS = process.env.TLS == 'true';
export const TLS =
typeof window !== 'undefined' && window.location.protocol === 'https:'
? true
: process.env.TLS == 'true';
Loading