diff --git a/client/.editorconfig b/.editorconfig similarity index 54% rename from client/.editorconfig rename to .editorconfig index d894f60..ed5a1d4 100644 --- a/client/.editorconfig +++ b/.editorconfig @@ -3,3 +3,9 @@ charset = utf-8 indent_style = tab indent_size = 2 quote_type= single + +[*.{go}] +charset = utf-8 +indent_style = tab +indent_size = 2 +quote_type= double diff --git a/.gitignore b/.gitignore index bfa451b..2602e06 100644 --- a/.gitignore +++ b/.gitignore @@ -8,9 +8,9 @@ lerna-debug.log* node_modules dist -dist-ssr +build *.local -.env +.env* # Editor directories and files .vscode/* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f7aff5b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM node:20-alpine AS frontend +WORKDIR /frontend +COPY ./client . +RUN npm install +RUN npm run build + +FROM golang:1.23-alpine AS backend +WORKDIR /backend +COPY ./server . +RUN go mod tidy +RUN go build -o server + +# FROM ollama/ollama:latest AS ai + +# Install the llama3.2:1b model +# RUN ollama pull llama3.2:1b + +# Stage 4: Setup NGINX to serve the React app and reverse proxy the Go and Ollama servers +FROM nginx:alpine AS reverse_proxy + +# Copy the React build from the previous stage to NGINX's HTML folder +COPY --from=frontend /frontend/build /usr/share/nginx/html + +# Copy the Go server binary into the container +COPY --from=backend /backend/.env.production .env +COPY --from=backend /backend/server /usr/local/bin/server + +# Copy NGINX configuration to configure reverse proxy +COPY ./nginx.conf /etc/nginx/nginx.conf + +# Expose necessary ports +EXPOSE 80 +EXPOSE 8080 + +# Start NGINX and Go server in parallel (using a simple entrypoint script) +CMD ["sh", "-c", "nginx -g 'daemon off;' & /usr/local/bin/server"] diff --git a/client/index.html b/client/index.html index 07d342e..42c7a34 100644 --- a/client/index.html +++ b/client/index.html @@ -16,8 +16,6 @@ property="og:description" content="Master touch typing with real code snippets from your favorite programming languages, powered by AI." > - - diff --git a/client/src/main.tsx b/client/src/main.tsx index 3ea4358..70a240f 100644 --- a/client/src/main.tsx +++ b/client/src/main.tsx @@ -6,7 +6,7 @@ import App from './App.tsx'; import './index.css'; // TODO: Bring back strict mode when building and deploying -createRoot(document.getElementById('root')).render( +createRoot(document.querySelector('#root') as HTMLElement).render( diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..3437e4c --- /dev/null +++ b/nginx.conf @@ -0,0 +1,31 @@ +events {} + +http { + upstream backend { + server 127.0.0.1:8080; + } + + upstream ai { + server 127.0.0.1:11434; + } + + server { + listen 80; + + location / { + root /usr/share/nginx/html; + try_files $uri $uri/ /index.html; + } + + location ~* \.(?:css|js)$ { + try_files $uri/ =404; + } + + location /api/ { + proxy_pass http://backend; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + } +} diff --git a/server/.editorconfig b/server/.editorconfig deleted file mode 100644 index 37197ff..0000000 --- a/server/.editorconfig +++ /dev/null @@ -1,5 +0,0 @@ -[*.{go}] -charset = utf-8 -indent_style = tab -indent_size = 2 -quote_type= double diff --git a/server/internal/handlers/generate.go b/server/internal/handlers/generate.go index 81c8c78..5888df0 100644 --- a/server/internal/handlers/generate.go +++ b/server/internal/handlers/generate.go @@ -135,7 +135,7 @@ func Generate(ctx echo.Context) error { return nil } - return ctx.String(http.StatusInternalServerError, "Error generating code!") + return ctx.String(http.StatusInternalServerError, "Error generating code: " + err.Error()) } return nil diff --git a/server/cmd/main.go b/server/main.go similarity index 76% rename from server/cmd/main.go rename to server/main.go index f35e0cb..13323db 100644 --- a/server/cmd/main.go +++ b/server/main.go @@ -15,7 +15,7 @@ func main() { err := godotenv.Load() if err != nil { - log.Fatal("Error loading environment!") + log.Fatal("Error loading environment: ", err.Error()) } PORT := os.Getenv("PORT") @@ -34,11 +34,11 @@ func main() { } ech.Logger.Fatal(ech.Start(fmt.Sprintf(":%s", PORT))) - } + } else { + if len(PORT) == 0 { + PORT = "4443" + } - if len(PORT) == 0 { - PORT = "4443" + ech.Logger.Fatal(ech.StartTLS(fmt.Sprintf(":%s", PORT), SSL_CERT_PATH, SSL_KEY_PATH)) } - - ech.Logger.Fatal(ech.StartTLS(fmt.Sprintf(":%s", PORT), SSL_CERT_PATH, SSL_KEY_PATH)) }