@harpy-js/core 0.5.3 → 0.5.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.
@@ -2,6 +2,7 @@ import type { NestFastifyApplication } from "@nestjs/platform-fastify";
2
2
  export interface HarpyAppOptions {
3
3
  layout?: any;
4
4
  distDir?: string;
5
+ publicDir?: string;
5
6
  }
6
7
  export declare function configureHarpyApp(app: NestFastifyApplication, opts?: HarpyAppOptions): Promise<void>;
7
8
  export declare function setupHarpyApp(app: NestFastifyApplication, opts?: HarpyAppOptions): Promise<void>;
@@ -52,7 +52,7 @@ catch (e) {
52
52
  }
53
53
  const jsx_engine_1 = require("./jsx.engine");
54
54
  async function configureHarpyApp(app, opts = {}) {
55
- const { layout, distDir = "dist" } = opts;
55
+ const { layout, distDir = "dist", publicDir } = opts;
56
56
  if (layout) {
57
57
  (0, jsx_engine_1.withJsxEngine)(app, layout);
58
58
  }
@@ -64,11 +64,20 @@ async function configureHarpyApp(app, opts = {}) {
64
64
  console.warn("[harpy-core] optional dependency `@fastify/cookie` is not installed; skipping cookie registration.");
65
65
  }
66
66
  if (fastifyStatic) {
67
- await fastify.register(fastifyStatic, {
68
- root: path.join(process.cwd(), distDir),
69
- prefix: "/",
70
- decorateReply: false,
71
- });
67
+ if (publicDir) {
68
+ await fastify.register(fastifyStatic, {
69
+ root: [path.join(process.cwd(), publicDir), path.join(process.cwd(), distDir)],
70
+ prefix: "/",
71
+ decorateReply: false,
72
+ });
73
+ }
74
+ else {
75
+ await fastify.register(fastifyStatic, {
76
+ root: path.join(process.cwd(), distDir),
77
+ prefix: "/",
78
+ decorateReply: false,
79
+ });
80
+ }
72
81
  }
73
82
  else {
74
83
  console.warn("[harpy-core] optional dependency `@fastify/static` is not installed; static `dist` handler not registered.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harpy-js/core",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Harpy - A powerful NestJS + React/JSX SSR framework with automatic hydration and i18n support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,6 +28,8 @@ export interface HarpyAppOptions {
28
28
  layout?: any;
29
29
  /** Folder containing built server assets (chunks) — defaults to `dist` */
30
30
  distDir?: string;
31
+ /** Optional folder containing public assets (favicon, manifest, etc.) */
32
+ publicDir?: string;
31
33
  }
32
34
 
33
35
  /**
@@ -43,7 +45,7 @@ export async function configureHarpyApp(
43
45
  app: NestFastifyApplication,
44
46
  opts: HarpyAppOptions = {},
45
47
  ) {
46
- const { layout, distDir = "dist" } = opts;
48
+ const { layout, distDir = "dist", publicDir } = opts;
47
49
 
48
50
  if (layout) {
49
51
  withJsxEngine(app, layout);
@@ -70,15 +72,23 @@ export async function configureHarpyApp(
70
72
  // This is important: hydration chunks are expected at the root ("/").
71
73
  // Use absolute path to be robust when invoked from different CWDs.
72
74
  if (fastifyStatic) {
73
- // Ensure hydration chunks and other built assets are served from `dist`
74
- // This is important: hydration chunks are expected at the root ("/").
75
- // Use absolute path to be robust when invoked from different CWDs.
76
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call
77
- await fastify.register(fastifyStatic, {
78
- root: path.join(process.cwd(), distDir),
79
- prefix: "/",
80
- decorateReply: false,
81
- });
75
+ // If publicDir is provided, register both directories
76
+ if (publicDir) {
77
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
78
+ await fastify.register(fastifyStatic, {
79
+ root: [path.join(process.cwd(), publicDir), path.join(process.cwd(), distDir)],
80
+ prefix: "/",
81
+ decorateReply: false,
82
+ });
83
+ } else {
84
+ // Only register dist directory
85
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
86
+ await fastify.register(fastifyStatic, {
87
+ root: path.join(process.cwd(), distDir),
88
+ prefix: "/",
89
+ decorateReply: false,
90
+ });
91
+ }
82
92
  } else {
83
93
  // If the static plugin is not available, emit a warning and continue.
84
94
  // Consumers who need hydration chunk serving in production should add