@eserstack/laroux-server 0.0.0-stage → 5.0.0
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/LICENSE +13 -0
- package/README.md +410 -2
- package/dist/adapters/react/error-chunk.d.ts +11 -0
- package/dist/adapters/react/error-chunk.js +12 -0
- package/dist/adapters/react/html-shell.d.ts +15 -0
- package/dist/adapters/react/html-shell.js +109 -0
- package/dist/adapters/react/inline-rsc-emitter.d.ts +62 -0
- package/dist/adapters/react/inline-rsc-emitter.js +120 -0
- package/dist/adapters/react/mod.d.ts +30 -0
- package/dist/adapters/react/mod.js +36 -0
- package/dist/adapters/react/render-app.d.ts +46 -0
- package/dist/adapters/react/render-app.js +44 -0
- package/dist/adapters/react/renderer.d.ts +15 -0
- package/dist/adapters/react/renderer.js +86 -0
- package/dist/adapters/react/rsc-flight-renderer.d.ts +64 -0
- package/dist/adapters/react/rsc-flight-renderer.js +623 -0
- package/dist/adapters/react/rsc-handler.d.ts +47 -0
- package/dist/adapters/react/rsc-handler.js +114 -0
- package/dist/adapters/react/script-json.d.ts +12 -0
- package/dist/adapters/react/script-json.js +18 -0
- package/dist/adapters/react/ssr-renderer.d.ts +63 -0
- package/dist/adapters/react/ssr-renderer.js +625 -0
- package/dist/bin-main.d.ts +1 -0
- package/dist/bin-main.js +18 -0
- package/dist/cli.d.ts +26 -0
- package/dist/cli.js +48 -0
- package/dist/commands/build.d.ts +78 -0
- package/dist/commands/build.js +221 -0
- package/dist/commands/dev.d.ts +50 -0
- package/dist/commands/dev.js +133 -0
- package/dist/commands/init.d.ts +29 -0
- package/dist/commands/init.js +228 -0
- package/dist/commands/serve.d.ts +47 -0
- package/dist/commands/serve.js +124 -0
- package/dist/config/load-config.d.ts +14 -0
- package/dist/config/load-config.js +67 -0
- package/dist/domain/action-registry.d.ts +83 -0
- package/dist/domain/action-registry.js +124 -0
- package/dist/domain/build-module.d.ts +30 -0
- package/dist/domain/build-module.js +50 -0
- package/dist/domain/hmr-manager.d.ts +51 -0
- package/dist/domain/hmr-manager.js +90 -0
- package/dist/domain/html-shell.d.ts +56 -0
- package/dist/domain/html-shell.js +15 -0
- package/dist/domain/middleware-dispatcher.d.ts +42 -0
- package/dist/domain/middleware-dispatcher.js +150 -0
- package/dist/domain/rebuild-handler.d.ts +52 -0
- package/dist/domain/rebuild-handler.js +52 -0
- package/dist/domain/renderer.d.ts +62 -0
- package/dist/domain/renderer.js +15 -0
- package/dist/domain/route-dispatcher.d.ts +40 -0
- package/dist/domain/route-dispatcher.js +134 -0
- package/dist/domain/server-modules.d.ts +65 -0
- package/dist/domain/server-modules.js +208 -0
- package/dist/main.d.ts +40 -0
- package/dist/main.js +256 -0
- package/dist/module.d.ts +24 -0
- package/dist/module.js +140 -0
- package/dist/options.d.ts +53 -0
- package/dist/options.js +14 -0
- package/dist/package.json +98 -0
- package/dist/proxy/types.d.ts +19 -0
- package/dist/proxy/types.js +3 -0
- package/dist/runtime/action-guard.d.ts +49 -0
- package/dist/runtime/action-guard.js +115 -0
- package/dist/runtime/html-shell.d.ts +66 -0
- package/dist/runtime/html-shell.js +246 -0
- package/dist/runtime/media-types.d.ts +13 -0
- package/dist/runtime/media-types.js +83 -0
- package/dist/runtime/path-containment.d.ts +11 -0
- package/dist/runtime/path-containment.js +27 -0
- package/dist/runtime/seo/generate-meta.d.ts +16 -0
- package/dist/runtime/seo/generate-meta.js +121 -0
- package/dist/runtime/seo/index.d.ts +5 -0
- package/dist/runtime/seo/index.js +5 -0
- package/dist/runtime/seo/types.d.ts +25 -0
- package/dist/runtime/seo/types.js +5 -0
- package/dist/runtime/server.d.ts +58 -0
- package/dist/runtime/server.js +699 -0
- package/package.json +81 -3
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* SEO metadata generator for Laroux.js
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Generate HTML meta tags from SEO config
|
|
7
|
+
*/
|
|
8
|
+
export function generateMetaTags(config, pageMetadata) {
|
|
9
|
+
const meta = { ...config, ...pageMetadata };
|
|
10
|
+
const tags = [];
|
|
11
|
+
// Basic meta tags
|
|
12
|
+
if (meta.description) {
|
|
13
|
+
tags.push(`<meta name="description" content="${escapeHtml(meta.description)}">`);
|
|
14
|
+
}
|
|
15
|
+
if (meta.keywords && meta.keywords.length > 0) {
|
|
16
|
+
tags.push(`<meta name="keywords" content="${escapeHtml(meta.keywords.join(", "))}">`);
|
|
17
|
+
}
|
|
18
|
+
if (meta.author) {
|
|
19
|
+
tags.push(`<meta name="author" content="${escapeHtml(meta.author)}">`);
|
|
20
|
+
}
|
|
21
|
+
if (meta.themeColor) {
|
|
22
|
+
tags.push(`<meta name="theme-color" content="${meta.themeColor}">`);
|
|
23
|
+
}
|
|
24
|
+
// Robots directives
|
|
25
|
+
const robotsDirectives = [];
|
|
26
|
+
if (meta.noIndex)
|
|
27
|
+
robotsDirectives.push("noindex");
|
|
28
|
+
if (meta.noFollow)
|
|
29
|
+
robotsDirectives.push("nofollow");
|
|
30
|
+
if (robotsDirectives.length > 0) {
|
|
31
|
+
tags.push(`<meta name="robots" content="${robotsDirectives.join(", ")}">`);
|
|
32
|
+
}
|
|
33
|
+
// Canonical URL
|
|
34
|
+
if (meta.canonicalUrl) {
|
|
35
|
+
tags.push(`<link rel="canonical" href="${escapeHtml(meta.canonicalUrl)}">`);
|
|
36
|
+
}
|
|
37
|
+
// Open Graph tags
|
|
38
|
+
tags.push(`<meta property="og:type" content="${meta.ogType ?? "website"}">`);
|
|
39
|
+
tags.push(`<meta property="og:title" content="${escapeHtml(meta.title)}">`);
|
|
40
|
+
if (meta.description) {
|
|
41
|
+
tags.push(`<meta property="og:description" content="${escapeHtml(meta.description)}">`);
|
|
42
|
+
}
|
|
43
|
+
if (meta.siteUrl) {
|
|
44
|
+
tags.push(`<meta property="og:url" content="${escapeHtml(meta.siteUrl)}">`);
|
|
45
|
+
}
|
|
46
|
+
if (meta.siteName) {
|
|
47
|
+
tags.push(`<meta property="og:site_name" content="${escapeHtml(meta.siteName)}">`);
|
|
48
|
+
}
|
|
49
|
+
if (meta.locale) {
|
|
50
|
+
tags.push(`<meta property="og:locale" content="${meta.locale}">`);
|
|
51
|
+
}
|
|
52
|
+
if (meta.ogImage) {
|
|
53
|
+
tags.push(`<meta property="og:image" content="${escapeHtml(meta.ogImage)}">`);
|
|
54
|
+
tags.push(`<meta property="og:image:alt" content="${escapeHtml(meta.title)}">`);
|
|
55
|
+
}
|
|
56
|
+
// Twitter Card tags
|
|
57
|
+
tags.push('<meta name="twitter:card" content="summary_large_image">');
|
|
58
|
+
tags.push(`<meta name="twitter:title" content="${escapeHtml(meta.title)}">`);
|
|
59
|
+
if (meta.description) {
|
|
60
|
+
tags.push(`<meta name="twitter:description" content="${escapeHtml(meta.description)}">`);
|
|
61
|
+
}
|
|
62
|
+
if (meta.twitterHandle) {
|
|
63
|
+
tags.push(`<meta name="twitter:site" content="${escapeHtml(meta.twitterHandle)}">`);
|
|
64
|
+
tags.push(`<meta name="twitter:creator" content="${escapeHtml(meta.twitterHandle)}">`);
|
|
65
|
+
}
|
|
66
|
+
if (meta.ogImage) {
|
|
67
|
+
tags.push(`<meta name="twitter:image" content="${escapeHtml(meta.ogImage)}">`);
|
|
68
|
+
}
|
|
69
|
+
// Favicon
|
|
70
|
+
if (meta.favicon) {
|
|
71
|
+
tags.push(`<link rel="icon" href="${escapeHtml(meta.favicon)}">`);
|
|
72
|
+
}
|
|
73
|
+
return tags.join("\n ");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Generate JSON-LD structured data
|
|
77
|
+
*/
|
|
78
|
+
export function generateJsonLd(config, pageMetadata) {
|
|
79
|
+
const meta = { ...config, ...pageMetadata };
|
|
80
|
+
// Default website structured data
|
|
81
|
+
const websiteSchema = {
|
|
82
|
+
"@context": "https://schema.org",
|
|
83
|
+
"@type": "WebSite",
|
|
84
|
+
name: meta.siteName,
|
|
85
|
+
url: meta.siteUrl,
|
|
86
|
+
description: meta.description,
|
|
87
|
+
};
|
|
88
|
+
// Organization schema
|
|
89
|
+
const organizationSchema = {
|
|
90
|
+
"@context": "https://schema.org",
|
|
91
|
+
"@type": "Organization",
|
|
92
|
+
name: meta.siteName,
|
|
93
|
+
url: meta.siteUrl,
|
|
94
|
+
logo: meta.ogImage,
|
|
95
|
+
};
|
|
96
|
+
// Combine with custom JSON-LD
|
|
97
|
+
const schemas = [websiteSchema, organizationSchema];
|
|
98
|
+
if (meta.jsonLd) {
|
|
99
|
+
schemas.push({
|
|
100
|
+
"@context": "https://schema.org",
|
|
101
|
+
...meta.jsonLd,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return schemas
|
|
105
|
+
.map((schema) =>
|
|
106
|
+
// "<" is escaped so a "</script>" inside any string value cannot close
|
|
107
|
+
// the tag.
|
|
108
|
+
`<script type="application/ld+json">${JSON.stringify(schema).replace(/</g, "\\u003c")}</script>`)
|
|
109
|
+
.join("\n ");
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Escape HTML special characters
|
|
113
|
+
*/
|
|
114
|
+
export function escapeHtml(text) {
|
|
115
|
+
return text
|
|
116
|
+
.replace(/&/g, "&")
|
|
117
|
+
.replace(/</g, "<")
|
|
118
|
+
.replace(/>/g, ">")
|
|
119
|
+
.replace(/"/g, """)
|
|
120
|
+
.replace(/'/g, "'");
|
|
121
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SEO types for Laroux.js
|
|
3
|
+
*/
|
|
4
|
+
export type SeoConfig = {
|
|
5
|
+
title: string;
|
|
6
|
+
description: string;
|
|
7
|
+
siteName: string;
|
|
8
|
+
siteUrl: string;
|
|
9
|
+
locale?: string;
|
|
10
|
+
themeColor?: string;
|
|
11
|
+
favicon?: string;
|
|
12
|
+
twitterHandle?: string;
|
|
13
|
+
ogImage?: string;
|
|
14
|
+
ogType?: "website" | "article" | "profile";
|
|
15
|
+
keywords?: string[];
|
|
16
|
+
author?: string;
|
|
17
|
+
canonicalUrl?: string;
|
|
18
|
+
noIndex?: boolean;
|
|
19
|
+
noFollow?: boolean;
|
|
20
|
+
jsonLd?: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
export type PageMetadata = Partial<SeoConfig> & {
|
|
23
|
+
title?: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Server for React Server Components
|
|
3
|
+
* Handles routing for HTML, RSC payloads, static assets, and Server Actions
|
|
4
|
+
*/
|
|
5
|
+
import * as crossRuntime from "@eserstack/standards/cross-runtime";
|
|
6
|
+
import type { AppConfig } from "../config/load-config.ts";
|
|
7
|
+
import type { HMRManager } from "../domain/hmr-manager.ts";
|
|
8
|
+
import type { Bundler } from "@eserstack/laroux-bundler";
|
|
9
|
+
import type { ApiRouteHandler } from "../domain/route-dispatcher.ts";
|
|
10
|
+
import type { MiddlewareDispatcher } from "../domain/middleware-dispatcher.ts";
|
|
11
|
+
import type { Renderer } from "../domain/renderer.ts";
|
|
12
|
+
import type { HtmlShellBuilder } from "../domain/html-shell.ts";
|
|
13
|
+
import type { RateLimitConfig } from "@eserstack/http/middlewares/rate-limiter";
|
|
14
|
+
import type { AppComponents } from "../domain/server-modules.ts";
|
|
15
|
+
/**
|
|
16
|
+
* Server dependencies container
|
|
17
|
+
*/
|
|
18
|
+
export type ServerDependencies = {
|
|
19
|
+
config: AppConfig;
|
|
20
|
+
bundler: Bundler;
|
|
21
|
+
getApp: (pathname: string) => Promise<AppComponents>;
|
|
22
|
+
/**
|
|
23
|
+
* Id of the build being served; it changes after each dev rebuild. Server
|
|
24
|
+
* action modules are imported with it, so a rebuilt action loads fresh.
|
|
25
|
+
*/
|
|
26
|
+
getBuildId: () => string;
|
|
27
|
+
hmrManager?: HMRManager | null;
|
|
28
|
+
apiHandler?: ApiRouteHandler;
|
|
29
|
+
middlewareDispatcher?: MiddlewareDispatcher;
|
|
30
|
+
renderer?: Renderer;
|
|
31
|
+
htmlShell?: HtmlShellBuilder;
|
|
32
|
+
rateLimitConfig?: RateLimitConfig | false;
|
|
33
|
+
};
|
|
34
|
+
/** Options for {@link createHandler}. */
|
|
35
|
+
export type CreateHandlerOptions = {
|
|
36
|
+
/**
|
|
37
|
+
* Stops the rate limiter's cleanup timer when aborted, so a stopped server
|
|
38
|
+
* lets the process exit.
|
|
39
|
+
*/
|
|
40
|
+
readonly signal?: AbortSignal;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Create request handler with injected dependencies
|
|
44
|
+
*/
|
|
45
|
+
export declare function createHandler(deps: ServerDependencies, options?: CreateHandlerOptions): (req: Request, info?: crossRuntime.ServeHandlerInfo) => Promise<Response>;
|
|
46
|
+
/** Options for {@link startHTTPServer}. */
|
|
47
|
+
export type StartHTTPServerOptions = {
|
|
48
|
+
/** Called with the bound address once the server listens. */
|
|
49
|
+
readonly onListen?: (addr: crossRuntime.NetAddr) => void;
|
|
50
|
+
/** Stops the server when aborted. */
|
|
51
|
+
readonly signal?: AbortSignal;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Start the HTTP server on `config.server.host` and `config.server.port`.
|
|
55
|
+
* The host is passed explicitly because runtime.http binds to 127.0.0.1 when
|
|
56
|
+
* none is given. Resolves once the server listens.
|
|
57
|
+
*/
|
|
58
|
+
export declare function startHTTPServer(deps: ServerDependencies, options?: StartHTTPServerOptions): Promise<crossRuntime.HttpServer>;
|