summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md125
1 files changed, 64 insertions, 61 deletions
diff --git a/README.md b/README.md
index 86b2b11..5e16435 100644
--- a/README.md
+++ b/README.md
@@ -1,75 +1,78 @@
-# React + TypeScript + Vite
+# Vite Portfolio (Headless Drupal Frontend)
-This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
+This project is configured to consume a headless Drupal backend (JSON:API) and deploy as a Docker image served by Nginx.
-Currently, two official plugins are available:
+## Added Drupal libraries
-- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
-- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
+- `axios` for HTTP requests
+- `drupal-jsonapi-params` for building Drupal JSON:API query parameters
-## React Compiler
+## Environment variables
-The React Compiler is enabled on this template. See [this documentation](https://react.dev/learn/react-compiler) for more information.
+Create a local env file from the template:
-Note: This will impact Vite dev & build performances.
+```bash
+cp .env.example .env.local
+```
+
+Available variables:
+
+- `VITE_DRUPAL_BASE_URL` (required) – base Drupal URL, for example `https://cms.example.com`
+- `VITE_DRUPAL_API_PREFIX` (optional) – defaults to `/jsonapi`
+- `VITE_DRUPAL_AUTH_TOKEN` (optional) – bearer token used by the HTTP client
+
+## Client utilities
+
+- Typed env config: `src/config/env.ts`
+- Reusable Drupal client: `src/lib/drupalClient.ts`
-## Expanding the ESLint configuration
+Example usage:
-If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
+```ts
+import { createDrupalParams, fetchDrupalResource } from './lib/drupalClient'
-```js
-export default defineConfig([
- globalIgnores(['dist']),
- {
- files: ['**/*.{ts,tsx}'],
- extends: [
- // Other configs...
+type NodeCollection = {
+ data: Array<{ id: string; attributes: Record<string, unknown> }>
+}
- // Remove tseslint.configs.recommended and replace with this
- tseslint.configs.recommendedTypeChecked,
- // Alternatively, use this for stricter rules
- tseslint.configs.strictTypeChecked,
- // Optionally, add this for stylistic rules
- tseslint.configs.stylisticTypeChecked,
+const params = createDrupalParams().addPageLimit(5).addFields('node--article', ['title'])
- // Other configs...
- ],
- languageOptions: {
- parserOptions: {
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
- tsconfigRootDir: import.meta.dirname,
- },
- // other options...
- },
- },
-])
+const articles = await fetchDrupalResource<NodeCollection>('/node/article', { params })
```
-You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
-
-```js
-// eslint.config.js
-import reactX from 'eslint-plugin-react-x'
-import reactDom from 'eslint-plugin-react-dom'
-
-export default defineConfig([
- globalIgnores(['dist']),
- {
- files: ['**/*.{ts,tsx}'],
- extends: [
- // Other configs...
- // Enable lint rules for React
- reactX.configs['recommended-typescript'],
- // Enable lint rules for React DOM
- reactDom.configs.recommended,
- ],
- languageOptions: {
- parserOptions: {
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
- tsconfigRootDir: import.meta.dirname,
- },
- // other options...
- },
- },
-])
+## Local development
+
+```bash
+bun install
+bun run dev
```
+
+## Docker build and run
+
+Pass Drupal variables at build time (Vite injects `VITE_*` during build):
+
+```bash
+docker build \
+ --build-arg VITE_DRUPAL_BASE_URL=https://cms.example.com \
+ --build-arg VITE_DRUPAL_API_PREFIX=/jsonapi \
+ --build-arg VITE_DRUPAL_AUTH_TOKEN=your-token \
+ -t vite-portfolio:latest .
+
+docker run --rm -p 8080:80 vite-portfolio:latest
+```
+
+## CI/CD deployment (GitHub Actions + Docker Swarm)
+
+The workflow in `.github/workflows/docker_build.yml` now forwards Drupal settings to Docker build args.
+
+Set these in your GitHub repository before deploying:
+
+- Repository variable: `VITE_DRUPAL_BASE_URL`
+- Repository variable: `VITE_DRUPAL_API_PREFIX` (optional)
+- Repository secret: `VITE_DRUPAL_AUTH_TOKEN` (optional)
+
+Existing deploy flow:
+
+1. Build and push image to GHCR on `main`
+2. SSH to the remote host
+3. `docker stack deploy -c docker-stack.yml vite-portfolio`