ionbeam 1.0.0-alpha.4 → 1.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/server/index.d.ts +4 -12
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +12 -20
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,17 +22,17 @@ npm install ionbeam
|
|
|
22
22
|
1. Create your server (`src/server.tsx`) with a simple route:
|
|
23
23
|
|
|
24
24
|
```tsx
|
|
25
|
-
import { createServer
|
|
25
|
+
import { createServer } from 'ionbeam';
|
|
26
26
|
import type { Request, Response } from 'express';
|
|
27
27
|
|
|
28
28
|
const app = createServer();
|
|
29
29
|
|
|
30
30
|
app.get('/', async (req: Request, res: Response) => {
|
|
31
|
-
await req.ionbeam.
|
|
32
|
-
|
|
31
|
+
await req.ionbeam.renderPage("Home",
|
|
32
|
+
<>
|
|
33
33
|
<h1>Home Page</h1>
|
|
34
34
|
<p>Built with IonBeam - A flexible React SSR framework</p>
|
|
35
|
-
|
|
35
|
+
</>
|
|
36
36
|
);
|
|
37
37
|
});
|
|
38
38
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { createServer, ionBeamMiddleware } from './server/index.js';
|
|
2
2
|
export type { ServerOptions, IonBeam } from './server/index.js';
|
|
3
|
-
export { Page } from './components/Page/index.js';
|
|
4
3
|
export { getAsset, getManifest } from './utils/manifest.js';
|
|
5
4
|
export { Builder } from './build/index.js';
|
|
6
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGhE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGpE,kBAAkB;AAClB,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE5D,qCAAqC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { JSX } from 'react/jsx-runtime';
|
|
2
1
|
import { Express, Request, Response, NextFunction } from 'express';
|
|
3
2
|
declare global {
|
|
4
3
|
namespace Express {
|
|
@@ -8,19 +7,12 @@ declare global {
|
|
|
8
7
|
}
|
|
9
8
|
}
|
|
10
9
|
export interface IonBeam {
|
|
11
|
-
|
|
10
|
+
renderElement: (element: React.ReactNode) => Promise<void>;
|
|
11
|
+
renderPage: (title: string, content: React.ReactNode) => Promise<void>;
|
|
12
12
|
}
|
|
13
13
|
export interface ServerOptions {
|
|
14
14
|
staticDir?: string;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* This allows route handlers to access assets and rendering utilities
|
|
19
|
-
*/
|
|
20
|
-
export declare function ionBeamMiddleware(options?: ServerOptions): (req: Request, res: Response, next: NextFunction) => void;
|
|
21
|
-
/**
|
|
22
|
-
* Create an Express server with IonBeam defaults
|
|
23
|
-
* Returns a configured Express app that you can customize
|
|
24
|
-
*/
|
|
25
|
-
export declare function createServer(options?: ServerOptions): Express;
|
|
16
|
+
export declare const ionBeamMiddleware: () => (req: Request, res: Response, next: NextFunction) => void;
|
|
17
|
+
export declare const createServer: (options?: ServerOptions) => Express;
|
|
26
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.tsx"],"names":[],"mappings":"AACA,OAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAO5E,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,OAAO,EAAE,OAAO,CAAC;SAClB;KACF;CACF;AAED,MAAM,WAAW,OAAO;IACtB,aAAa,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACxE;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,iBAAiB,SACpB,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,SAqBxD,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,UAAS,aAAkB,KAAG,OAW1D,CAAA"}
|
package/dist/server/index.js
CHANGED
|
@@ -4,39 +4,31 @@ import { prerenderToNodeStream } from 'react-dom/static';
|
|
|
4
4
|
import { getAsset } from '../utils/manifest.js';
|
|
5
5
|
import { AssetsProvider } from '../utils/assets-context.js';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* This allows route handlers to access assets and rendering utilities
|
|
10
|
-
*/
|
|
11
|
-
export function ionBeamMiddleware(options = {}) {
|
|
7
|
+
import { Page } from '../components/Page/index.js';
|
|
8
|
+
export const ionBeamMiddleware = () => {
|
|
12
9
|
return (req, res, next) => {
|
|
13
10
|
const clientScript = getAsset('client.js');
|
|
14
11
|
const styleSheet = getAsset('server.css');
|
|
15
|
-
console.log('IonBeam Middleware: Attaching IonBeam context to request');
|
|
16
|
-
console.log(` - Client Script: ${clientScript}`);
|
|
17
|
-
console.log(` - Style Sheet: ${styleSheet}`);
|
|
18
12
|
req.ionbeam = {
|
|
19
|
-
|
|
20
|
-
const { prelude } = await prerenderToNodeStream(_jsx(AssetsProvider, { value: { clientScript, styleSheet }, children: element }));
|
|
13
|
+
renderPage: async (title, element) => {
|
|
14
|
+
const { prelude } = await prerenderToNodeStream(_jsx(AssetsProvider, { value: { clientScript, styleSheet }, children: _jsx(Page, { title: title, children: element }) }));
|
|
21
15
|
prelude.pipe(res);
|
|
22
16
|
},
|
|
17
|
+
renderElement: async (element) => {
|
|
18
|
+
const { prelude } = await prerenderToNodeStream(element);
|
|
19
|
+
prelude.pipe(res);
|
|
20
|
+
}
|
|
23
21
|
};
|
|
24
22
|
next();
|
|
25
23
|
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
* Create an Express server with IonBeam defaults
|
|
29
|
-
* Returns a configured Express app that you can customize
|
|
30
|
-
*/
|
|
31
|
-
export function createServer(options = {}) {
|
|
24
|
+
};
|
|
25
|
+
export const createServer = (options = {}) => {
|
|
32
26
|
const app = express();
|
|
33
27
|
const staticDir = options.staticDir || path.join(process.cwd(), 'dist', 'static');
|
|
34
|
-
// Default middleware
|
|
35
28
|
app.use(express.static(staticDir));
|
|
36
29
|
app.use(express.urlencoded({ extended: true }));
|
|
37
30
|
app.use(express.json());
|
|
38
|
-
|
|
39
|
-
app.use(ionBeamMiddleware(options));
|
|
31
|
+
app.use(ionBeamMiddleware());
|
|
40
32
|
return app;
|
|
41
|
-
}
|
|
33
|
+
};
|
|
42
34
|
//# sourceMappingURL=index.js.map
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.tsx"],"names":[],"mappings":";AACA,OAAO,OAAqD,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,IAAI,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.tsx"],"names":[],"mappings":";AACA,OAAO,OAAqD,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAmBnD,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,OAAO,CAAC,GAAY,EAAE,G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