Skip to content

Commit ef0c37c

Browse files
committed
Add browser package tab and docs page
1 parent 8130ba9 commit ef0c37c

3 files changed

Lines changed: 66 additions & 1 deletion

File tree

src/components/CodeTabs.astro

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
import { Code } from 'astro:components';
33
4-
const tabs = ['Node.js', 'NestJS', 'PHP', 'Laravel', 'HTTP API'] as const;
4+
const tabs = ['Node.js', 'NestJS', 'PHP', 'Laravel', 'Browser', 'HTTP API'] as const;
55
66
const snippets: Record<string, { lang: string; code: string }> = {
77
'Node.js': {
@@ -48,6 +48,16 @@ FANAR_HOST=127.0.0.1
4848
FANAR_PORT=9913
4949
5050
// Auto-logs every request, query, and exception`,
51+
},
52+
'Browser': {
53+
lang: 'html',
54+
code: `<script src="https://cdn.jsdelivr.net/npm/@fanar-app/fanar-browser/dist/fanar.js"></script>
55+
<script>
56+
fanar('hello from the browser')
57+
fanar({ user, cart }).label('checkout')
58+
fanar(new Error('something went wrong'))
59+
fanar.time('render').stop()
60+
</script>`,
5161
},
5262
'HTTP API': {
5363
lang: 'bash',

src/components/DocsLayout.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const nav = [
1818
{ label: 'PHP', href: '/docs/php/', id: 'php', group: 'client' },
1919
{ label: 'Laravel', href: '/docs/laravel/', id: 'laravel', group: 'client' },
2020
{ label: 'Python', href: '/docs/python/', id: 'python', group: 'client' },
21+
{ label: 'Browser', href: '/docs/browser/', id: 'browser', group: 'client' },
2122
{ label: 'HTTP API', href: '/docs/http-api/', id: 'http-api', group: null },
2223
{ label: 'Configuration', href: '/docs/configuration/', id: 'configuration', group: null },
2324
{ label: 'SSH Tunnel', href: '/docs/ssh/', id: 'ssh', group: null },

src/pages/docs/browser.astro

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
import DocsLayout from '../../components/DocsLayout.astro';
3+
import { Code } from 'astro:components';
4+
---
5+
6+
<DocsLayout title="Browser" section="browser">
7+
<h1>Browser</h1>
8+
<p class="lead">Drop a script tag into any page — or import as an ES module. Same API as the Node.js client. No build step required.</p>
9+
10+
<h2>Script tag (CDN)</h2>
11+
<Code code={`<script src="https://cdn.jsdelivr.net/npm/@fanar-app/fanar-browser/dist/fanar.js"></script>
12+
<script>
13+
fanar('hello from the browser')
14+
fanar({ user, cart }).label('checkout')
15+
fanar(new Error('something went wrong'))
16+
fanar.time('render').stop()
17+
</script>`} lang="html" theme="github-dark" />
18+
19+
<h2>ES module</h2>
20+
<Code code={`<script type="module">
21+
import fanar from 'https://cdn.jsdelivr.net/npm/@fanar-app/fanar-browser/dist/index.js'
22+
23+
fanar('hello')
24+
fanar({ user, cart }).label('checkout')
25+
fanar.time('render').stop()
26+
</script>`} lang="html" theme="github-dark" />
27+
28+
<h2>npm</h2>
29+
<Code code={`npm install @fanar-app/fanar-browser`} lang="bash" theme="github-dark" />
30+
<Code code={`import fanar from '@fanar-app/fanar-browser'
31+
32+
fanar('hello')
33+
fanar({ user, session }).label('auth')
34+
fanar(new Error('oops'))
35+
fanar.time('paint').stop()`} lang="javascript" theme="github-dark" />
36+
37+
<h2>API</h2>
38+
<table>
39+
<tr><th>Call</th><th>Description</th></tr>
40+
<tr><td>fanar(value)</td><td>Auto-dispatch — string/number → log, object → dump, Error → exception</td></tr>
41+
<tr><td>.label(str)</td><td>Chain a label onto any call</td></tr>
42+
<tr><td>.color(str)</td><td>Chain a color tag onto any call</td></tr>
43+
<tr><td>fanar.time(label)</td><td>Start a named timer — call <code>.stop()</code> to send elapsed ms</td></tr>
44+
<tr><td>fanar.query(sql, opts)</td><td>Send a SQL query with optional bindings and duration</td></tr>
45+
<tr><td>fanar.clear()</td><td>Clear all payloads in the Fanar app</td></tr>
46+
<tr><td>fanar.configure(opts)</td><td>Set <code>host</code> and <code>port</code> (default: <code>localhost:23517</code>)</td></tr>
47+
</table>
48+
49+
<h2>Configuration</h2>
50+
<Code code={`fanar.configure({ host: '192.168.1.5', port: 23517 })`} lang="javascript" theme="github-dark" />
51+
52+
<h2>CORS</h2>
53+
<p>The Fanar app must have CORS enabled to accept requests from browser pages. This is on by default for <code>localhost</code> origins. For remote hosts, set <code>FANAR_CORS_ORIGIN</code> in the Fanar app config.</p>
54+
</DocsLayout>

0 commit comments

Comments
 (0)