Skip to content

Commit 4af207e

Browse files
Astro example integration with Dynamia
1 parent b75177b commit 4af207e

File tree

15 files changed

+6578
-0
lines changed

15 files changed

+6578
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# demo-client-books backend API URL — override for production
2+
PUBLIC_API_URL=https://your-demo-zk-books.example.com
3+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
dist/
3+
.env
4+
.env.local
5+
.astro/
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# demo-client-books
2+
3+
> Public storefront demo built with **Astro** + **@dynamia-tools/sdk**, consuming the [`demo-zk-books`](../demo-zk-books) backend.
4+
5+
---
6+
7+
## What it shows
8+
9+
| Page | URL | Description |
10+
|------|-----|-------------|
11+
| Home | `/` | Featured books grid with category filter and pagination |
12+
| Books | `/books` | Full catalog with search, category filter and pagination |
13+
| Book detail | `/books/:id` | Cover, price, stock status, synopsis and reader reviews |
14+
| Categories | `/categories` | All categories with links to filtered book list |
15+
16+
Everything is **server-rendered** (SSR via `@astrojs/node`), so each request fetches live data from the Dynamia Platform REST API via `@dynamia-tools/sdk`.
17+
18+
---
19+
20+
## Prerequisites
21+
22+
- Node.js ≥ 20
23+
- [`demo-zk-books`](../demo-zk-books) backend running (defaults to `http://localhost:8080`)
24+
25+
---
26+
27+
## Quick start
28+
29+
```bash
30+
# 1 – Install dependencies
31+
npm install
32+
33+
# 2 – Point to your backend (edit .env or set the env var)
34+
echo "PUBLIC_API_URL=http://localhost:8484" > .env
35+
36+
# 3 – Dev server with hot-reload
37+
npm run dev # http://localhost:4321
38+
39+
# 4 – Production build
40+
npm run build
41+
node dist/server/entry.mjs
42+
```
43+
44+
---
45+
46+
## Project structure
47+
48+
```
49+
demo-client-books/
50+
├── src/
51+
│ ├── layouts/
52+
│ │ └── Layout.astro # Navbar, footer, global CSS
53+
│ ├── lib/
54+
│ │ ├── client.ts # DynamiaClient singleton (reads PUBLIC_API_URL)
55+
│ │ ├── types.ts # TypeScript types mirroring Java domain
56+
│ │ └── api.ts # Thin helpers: getBooks(), getCoverUrl(), ...
57+
│ └── pages/
58+
│ ├── index.astro # Home / featured books
59+
│ ├── books/
60+
│ │ ├── index.astro # /books — full catalog
61+
│ │ └── [id].astro # /books/:id — book detail
62+
│ └── categories/
63+
│ └── index.astro # /categories
64+
├── .env # PUBLIC_API_URL (git-ignored)
65+
├── .env.example # Template
66+
├── astro.config.mjs
67+
├── package.json
68+
└── tsconfig.json
69+
```
70+
71+
---
72+
73+
## SDK usage
74+
75+
```typescript
76+
import { DynamiaClient } from '@dynamia-tools/sdk';
77+
78+
const client = new DynamiaClient({ baseUrl: 'http://localhost:8080' });
79+
80+
// List books (CrudPage virtual path: "library/books")
81+
const { content, total } = await client.crud('library/books').findAll({ page: 1, size: 12 });
82+
83+
// Single book
84+
const book = await client.crud('library/books').findById(1);
85+
86+
// File cover URL
87+
const url = client.files.getUrl(book.bookCover.filename, book.bookCover.uuid);
88+
```
89+
90+
---
91+
92+
## License
93+
94+
Apache 2.0 — © Dynamia Soluciones IT SAS
95+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig } from 'astro/config';
2+
import node from '@astrojs/node';
3+
4+
// https://astro.build/config
5+
export default defineConfig({
6+
output: 'server',
7+
adapter: node({ mode: 'standalone' }),
8+
server: {
9+
port: 4321,
10+
},
11+
});
12+
13+

0 commit comments

Comments
 (0)