From d8bade023f382b76470ed0c6a16bb91298e0bf56 Mon Sep 17 00:00:00 2001 From: "cloudflare-workers-and-pages[bot]" <73139402+cloudflare-workers-and-pages[bot]@users.noreply.github.com> Date: Fri, 24 Jul 2026 01:03:03 +0000 Subject: [PATCH 1/2] Add Cloudflare Workers configuration --- front/.gitignore | 9 +++++- front/package.json | 71 ++++++++++++++++++++++---------------------- front/vite.config.ts | 9 +++--- front/wrangler.jsonc | 14 +++++++++ front/yarn.lock | 24 +++++++++++++-- 5 files changed, 84 insertions(+), 43 deletions(-) create mode 100644 front/wrangler.jsonc diff --git a/front/.gitignore b/front/.gitignore index 8cf7502..9dc7d65 100644 --- a/front/.gitignore +++ b/front/.gitignore @@ -22,4 +22,11 @@ dist-ssr *.njsproj *.sln *.sw? -*.gz \ No newline at end of file +*.gz + +# wrangler files +.wrangler +.dev.vars* +!.dev.vars.example +.env* +!.env.example diff --git a/front/package.json b/front/package.json index 4060a6a..20f4fab 100644 --- a/front/package.json +++ b/front/package.json @@ -1,37 +1,38 @@ { - "name": "front", - "private": true, - "version": "0.0.1", - "packageManager": "yarn@4.17.1", - "type": "module", - "scripts": { - "dev": "vite", - "build": "tsc -b && vite build", - "deploy": "wrangler deploy", - "lint": "eslint .", - "preview": "vite preview" - }, - "dependencies": { - "@rolldown/plugin-babel": "^0.2.3", - "react": "^19.2.4", - "react-dom": "^19.2.4" - }, - "devDependencies": { - "@babel/core": "^7.29.0", - "@eslint/js": "^9.39.4", - "@types/babel__core": "^7.20.5", - "@types/node": "^24.12.0", - "@types/react": "^19.2.14", - "@types/react-dom": "^19.2.3", - "@vitejs/plugin-react": "^6.0.0", - "babel-plugin-react-compiler": "^1.0.0", - "eslint": "^9.39.4", - "eslint-plugin-react-hooks": "^7.0.1", - "eslint-plugin-react-refresh": "^0.5.2", - "globals": "^17.4.0", - "typescript": "~5.9.3", - "typescript-eslint": "^8.56.1", - "vite": "^8.0.0", - "wrangler": "^4.17.1" - } + "name": "front", + "private": true, + "version": "0.0.1", + "packageManager": "yarn@4.17.1", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc -b && vite build", + "deploy": "yarn run build && wrangler deploy", + "lint": "eslint .", + "preview": "yarn run build && wrangler dev" + }, + "dependencies": { + "@rolldown/plugin-babel": "^0.2.3", + "react": "^19.2.4", + "react-dom": "^19.2.4" + }, + "devDependencies": { + "@babel/core": "^7.29.0", + "@cloudflare/vite-plugin": "^1.47.0", + "@eslint/js": "^9.39.4", + "@types/babel__core": "^7.20.5", + "@types/node": "^24.12.0", + "@types/react": "^19.2.14", + "@types/react-dom": "^19.2.3", + "@vitejs/plugin-react": "^6.0.0", + "babel-plugin-react-compiler": "^1.0.0", + "eslint": "^9.39.4", + "eslint-plugin-react-hooks": "^7.0.1", + "eslint-plugin-react-refresh": "^0.5.2", + "globals": "^17.4.0", + "typescript": "~5.9.3", + "typescript-eslint": "^8.56.1", + "vite": "^8.0.0", + "wrangler": "^4.114.0" + } } diff --git a/front/vite.config.ts b/front/vite.config.ts index d1203cd..ad9c31b 100644 --- a/front/vite.config.ts +++ b/front/vite.config.ts @@ -2,10 +2,9 @@ import { defineConfig } from 'vite' import react, { reactCompilerPreset } from '@vitejs/plugin-react' import babel from '@rolldown/plugin-babel' +import { cloudflare } from "@cloudflare/vite-plugin"; + // https://vite.dev/config/ export default defineConfig({ - plugins: [ - react(), - babel({ presets: [reactCompilerPreset()] }) - ], -}) + plugins: [react(), babel({ presets: [reactCompilerPreset()] }), cloudflare()], +}) \ No newline at end of file diff --git a/front/wrangler.jsonc b/front/wrangler.jsonc new file mode 100644 index 0000000..abdabea --- /dev/null +++ b/front/wrangler.jsonc @@ -0,0 +1,14 @@ +{ + "$schema": "node_modules/wrangler/config-schema.json", + "name": "doc-rag", + "compatibility_date": "2026-07-24", + "observability": { + "enabled": true + }, + "assets": { + "not_found_handling": "single-page-application" + }, + "compatibility_flags": [ + "nodejs_compat" + ] +} diff --git a/front/yarn.lock b/front/yarn.lock index b6faa29..e5bb7f5 100644 --- a/front/yarn.lock +++ b/front/yarn.lock @@ -200,6 +200,25 @@ __metadata: languageName: node linkType: hard +"@cloudflare/vite-plugin@npm:^1.47.0": + version: 1.47.0 + resolution: "@cloudflare/vite-plugin@npm:1.47.0" + dependencies: + "@cloudflare/unenv-preset": "npm:2.16.1" + miniflare: "npm:4.20260722.0" + unenv: "npm:2.0.0-rc.24" + workerd: "npm:1.20260722.1" + wrangler: "npm:4.114.0" + ws: "npm:8.21.0" + peerDependencies: + vite: ^6.1.0 || ^7.0.0 || ^8.0.0 + wrangler: ^4.114.0 + bin: + cf-vite: bin/cf-vite + checksum: 10c0/1748d51fbee3b37769b437e6f6f87aaed1a69b0df404fd948ff1ae4fb16a8985403e8d88999348d89e7a67ca6e3d91da7b8b8e906ce4810e04e2c880ed450737 + languageName: node + linkType: hard + "@cloudflare/workerd-darwin-64@npm:1.20260722.1": version: 1.20260722.1 resolution: "@cloudflare/workerd-darwin-64@npm:1.20260722.1" @@ -1933,6 +1952,7 @@ __metadata: resolution: "front@workspace:." dependencies: "@babel/core": "npm:^7.29.0" + "@cloudflare/vite-plugin": "npm:^1.47.0" "@eslint/js": "npm:^9.39.4" "@rolldown/plugin-babel": "npm:^0.2.3" "@types/babel__core": "npm:^7.20.5" @@ -1950,7 +1970,7 @@ __metadata: typescript: "npm:~5.9.3" typescript-eslint: "npm:^8.56.1" vite: "npm:^8.0.0" - wrangler: "npm:^4.17.1" + wrangler: "npm:^4.114.0" languageName: unknown linkType: soft @@ -3064,7 +3084,7 @@ __metadata: languageName: node linkType: hard -"wrangler@npm:^4.17.1": +"wrangler@npm:4.114.0, wrangler@npm:^4.114.0": version: 4.114.0 resolution: "wrangler@npm:4.114.0" dependencies: From 7534ba18e8bf90c989e55ab0ee3ceade3e2e56c9 Mon Sep 17 00:00:00 2001 From: alrafiabdullah Date: Fri, 24 Jul 2026 03:29:57 +0200 Subject: [PATCH 2/2] Update README --- README.md | 14 ++++++++++++-- app/README.md | 6 ++++++ front/README.md | 9 +++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1d7567a..a617a73 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ This repository contains a complete Retrieval-Augmented Generation (RAG) workflo The system accepts only `.txt` and `.pdf`, does not persist uploaded files, and supports streamed answers. +The frontend is managed with Yarn 4.17.1 through Corepack and is deployed with Wrangler. The main CI workflow validates the backend with pytest and the frontend with a Yarn 4 immutable install plus a production build. + ## Repository Structure - `app/` FastAPI backend for RAG queries @@ -23,14 +25,15 @@ The system accepts only `.txt` and `.pdf`, does not persist uploaded files, and ## Prerequisites - Python 3.10+ -- Node.js 24+ and Yarn +- Node.js 24+ +- Corepack-enabled Yarn 4.17.1 - A Hugging Face token ## 1) Clone and Install ```bash git clone -cd nlp_projects +cd doc_rag pip install -r requirements.txt cd front yarn install @@ -55,6 +58,12 @@ yarn dev Open the URL printed by Vite (typically http://localhost:5173). +To deploy the frontend through Cloudflare from the `front/` directory: + +```bash +yarn deploy +``` + ## 4) Use the App - Paste your Hugging Face token in the frontend (stored in browser localStorage) @@ -76,6 +85,7 @@ Optional backend variables: ## Notes - Uploaded files are processed in-memory and are not stored by the API. +- Frontend install and build should use Yarn 4.17.1 with Corepack enabled. - Frontend build check: ```bash cd front diff --git a/app/README.md b/app/README.md index e4eb3a2..814ea8e 100644 --- a/app/README.md +++ b/app/README.md @@ -21,6 +21,8 @@ From repository root: uvicorn app.main:app --reload ``` +The frontend lives in `front/` and uses Yarn 4.17.1 with Corepack. For the frontend install, build, and deploy commands, see [front/README.md](../front/README.md). + ## API Contract `POST /rag/query` multipart form fields: @@ -42,6 +44,10 @@ If `hf_token` is omitted, backend tries `HUGGINGFACE_API_KEY`/`HF_TOKEN`/`HUGGIN - Keep real secrets in deployment environment variables. - Rotate the token immediately if it is ever exposed. +## CI Notes + +The repository workflow runs backend tests with pytest and validates the frontend with a Yarn 4 immutable install followed by a production build. + ## Useful Endpoints - `GET /docs` (private; requires `DOCS_ACCESS_TOKEN`) diff --git a/front/README.md b/front/README.md index 9931eb6..11eb8d9 100644 --- a/front/README.md +++ b/front/README.md @@ -2,6 +2,8 @@ This folder contains the mobile-friendly UI for the RAG system. +The frontend uses Yarn 4.17.1 via Corepack, and the deploy script runs Wrangler from this directory. + ## What It Does - Lets users provide Hugging Face token (stored in browser localStorage) @@ -13,9 +15,12 @@ This folder contains the mobile-friendly UI for the RAG system. ```bash cd front +yarn --version yarn install ``` +If Corepack is not already enabled, run `corepack enable` once in your environment before installing. + ## Run (Development) ```bash @@ -29,6 +34,8 @@ yarn build yarn preview ``` +`yarn deploy` runs the production build and then executes `wrangler deploy`. + ## Backend URL The app uses `VITE_API_URL` if provided, otherwise defaults to: @@ -41,6 +48,8 @@ To override: VITE_API_URL="https://your-backend-domain/rag/query" VITE_MAX_FILE_SIZE_MB=1 VITE_RATE_LIMIT_MAX_REQUESTS=10 yarn dev ``` +The CI workflow uses `yarn install --immutable` and `yarn build` in `front/`. + ## Notes - Token is saved in browser localStorage key `hf_token`.