@alignable/bifrost-fastify 0.0.22 → 0.0.23

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/dist/index.js CHANGED
@@ -19,8 +19,8 @@ async function replyWithPage(reply, pageContext) {
19
19
  if (!httpResponse) {
20
20
  return reply.code(404).type("text/html").send("Not Found");
21
21
  }
22
- const { body, statusCode, contentType } = httpResponse;
23
- return reply.status(statusCode).type(contentType).send(body);
22
+ const { body, statusCode, headers } = httpResponse;
23
+ return reply.status(statusCode).headers(Object.fromEntries(headers)).send(body);
24
24
  }
25
25
  var proxyPageId = "/proxy/pages";
26
26
  var viteProxyPlugin = async (fastify, { upstream, host, buildPageContextInit, rewriteRequestHeaders, getLayout }) => {
@@ -29,12 +29,6 @@ var viteProxyPlugin = async (fastify, { upstream, host, buildPageContextInit, re
29
29
  upstream: upstream.href,
30
30
  async preHandler(req, reply) {
31
31
  if (req.method === "GET" && req.accepts().type(["html"]) === "html") {
32
- const trailingSlash = /\/(\?|#|$)/;
33
- if (trailingSlash.test(req.url)) {
34
- req.log.info("bifrost: redirecting trailing slash");
35
- reply.redirect(301, req.url.replace(trailingSlash, "$1"));
36
- return;
37
- }
38
32
  const pageContextInit = {
39
33
  urlOriginal: req.url,
40
34
  ...buildPageContextInit ? await buildPageContextInit(req) : {}
@@ -91,12 +85,10 @@ var viteProxyPlugin = async (fastify, { upstream, host, buildPageContextInit, re
91
85
  }
92
86
  reply.header("location", url);
93
87
  if (isPageContext) {
94
- reply.status(200).type("application/json").send(
88
+ return reply.status(200).type("application/json").send(
95
89
  JSON.stringify({
96
- pageContext: {
97
- _pageId: proxyPageId,
98
- redirectTo: url
99
- }
90
+ _pageId: proxyPageId,
91
+ redirectTo: url
100
92
  })
101
93
  );
102
94
  } else {
@@ -108,17 +100,18 @@ var viteProxyPlugin = async (fastify, { upstream, host, buildPageContextInit, re
108
100
  if (!layout) {
109
101
  return reply.send(res);
110
102
  }
111
- const proxy2 = await streamToString(res);
103
+ const html = await streamToString(res);
112
104
  const pageContextInit = {
113
105
  urlOriginal: req.url,
114
- layout,
115
- layoutProps
106
+ // Nest into fromProxy to avoid triggering pageContextInitHasClientData which forces restorationVisit to refetch pageContext
107
+ // Ideally we would just set restorationVisit onBeforeRender to no-op
108
+ // https://github.com/brillout/vite-plugin-ssr/discussions/1075#discussioncomment-6758711
109
+ fromProxy: {
110
+ layout,
111
+ layoutProps,
112
+ html
113
+ }
116
114
  };
117
- if (isPageContext) {
118
- Object.assign(pageContextInit, { proxySendClient: proxy2 });
119
- } else {
120
- Object.assign(pageContextInit, { proxy: proxy2 });
121
- }
122
115
  const pageContext = await renderPage(pageContextInit);
123
116
  return replyWithPage(reply, pageContext);
124
117
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts"],"sourcesContent":["// Note that this file isn't processed by Vite, see https://github.com/brillout/vite-plugin-ssr/issues/562\nimport { FastifyReply, RawServerBase, FastifyPluginAsync } from \"fastify\";\nimport { FastifyRequest, RequestGenericInterface } from \"fastify/types/request\";\nimport proxy from \"@fastify/http-proxy\";\nimport accepts from \"@fastify/accepts\";\nimport { type PageContextProxy } from \"../bifrost/types/internal.js\";\nimport forwarded from \"@fastify/forwarded\";\nimport { Writable } from \"stream\";\nimport { IncomingHttpHeaders, IncomingMessage } from \"http\";\nimport {\n Http2ServerRequest,\n IncomingHttpHeaders as Http2IncomingHttpHeaders,\n} from \"http2\";\nimport { renderPage } from \"vite-plugin-ssr/server\";\nimport { AugmentMe } from \"@alignable/bifrost\";\n\ntype RequestExtendedWithProxy = FastifyRequest<\n RequestGenericInterface,\n RawServerBase\n> & { _proxy?: { isPageContext: boolean; originalUrl?: string } };\n\nfunction streamToString(stream: Writable): Promise<string> {\n const chunks: Buffer[] = [];\n return new Promise((resolve, reject) => {\n stream.on(\"data\", (chunk) => chunks.push(Buffer.from(chunk)));\n stream.on(\"error\", (err) => reject(err));\n stream.on(\"end\", () => resolve(Buffer.concat(chunks).toString(\"utf8\")));\n });\n}\n\nasync function replyWithPage(\n reply: FastifyReply<RawServerBase>,\n pageContext: Awaited<\n ReturnType<\n typeof renderPage<\n { redirectTo?: string; isClientSideNavigation?: boolean },\n {}\n >\n >\n >\n): Promise<FastifyReply> {\n const { httpResponse } = pageContext;\n\n if (pageContext.redirectTo && !pageContext.isClientSideNavigation) {\n return reply.redirect(307, pageContext.redirectTo);\n }\n\n if (!httpResponse) {\n return reply.code(404).type(\"text/html\").send(\"Not Found\");\n }\n\n const { body, statusCode, contentType } = httpResponse;\n return reply.status(statusCode).type(contentType).send(body);\n}\n\nconst proxyPageId = \"/proxy/pages\";\n\ninterface ViteProxyPluginOptions {\n upstream: URL;\n host: URL;\n buildPageContextInit?: (\n req: FastifyRequest\n ) => Promise<AugmentMe.PageContextInit>;\n getLayout: (reply: FastifyReply<RawServerBase>) => {\n layout: string;\n layoutProps: AugmentMe.LayoutProps;\n };\n /// Use to signal to legacy backend to return special results (eg. remove navbar etc)\n rewriteRequestHeaders?: (\n req: Http2ServerRequest | IncomingMessage,\n headers: Http2IncomingHttpHeaders | IncomingHttpHeaders\n ) => Http2IncomingHttpHeaders | IncomingHttpHeaders;\n}\n/**\n * Fastify plugin that wraps @fasitfy/http-proxy to proxy Rails/Turbolinks server into a Vite-Plugin-SSR site.\n */\nexport const viteProxyPlugin: FastifyPluginAsync<\n ViteProxyPluginOptions\n> = async (\n fastify,\n { upstream, host, buildPageContextInit, rewriteRequestHeaders, getLayout }\n) => {\n await fastify.register(accepts);\n await fastify.register(proxy, {\n upstream: upstream.href,\n async preHandler(req, reply) {\n if (req.method === \"GET\" && req.accepts().type([\"html\"]) === \"html\") {\n const trailingSlash = /\\/(\\?|#|$)/;\n\n if (trailingSlash.test(req.url)) {\n req.log.info(\"bifrost: redirecting trailing slash\");\n reply.redirect(301, req.url.replace(trailingSlash, \"\\$1\"));\n return;\n }\n\n const pageContextInit = {\n urlOriginal: req.url,\n ...(buildPageContextInit ? await buildPageContextInit(req) : {}),\n };\n\n const pageContext = await renderPage<\n { _pageId: string },\n typeof pageContextInit\n >(pageContextInit);\n\n const proxy = pageContext._pageId === proxyPageId;\n const noRouteMatched =\n (pageContext as any).is404 && !pageContext.errorWhileRendering; // we hit no page, but NOT because of an error\n\n if (noRouteMatched) {\n req.log.info(\"bifrost: no route match, naked proxy to backend\");\n // Naked proxy\n return;\n } else if (!proxy) {\n req.log.info(`bifrost: rendering page ${pageContext._pageId}`);\n return replyWithPage(reply, pageContext);\n } else {\n req.log.info(`bifrost: proxy route matched, proxying to backend`);\n // pageContext.json is added on client navigations to indicate we are returning just json for the client router\n // we have to remove it before proxying though.\n (req as RequestExtendedWithProxy)._proxy = {\n isPageContext: req.raw.url!.includes(\"/index.pageContext.json\"),\n originalUrl: req.raw.url,\n };\n (req.raw as any)._proxy = true;\n req.raw.url = req.raw.url!.replace(\"/index.pageContext.json\", \"\");\n }\n }\n },\n replyOptions: {\n rewriteRequestHeaders(request, headers) {\n const fwd = forwarded(request as IncomingMessage).reverse();\n // fwd.push(request.ip); TODO: not sure if this is needed\n headers[\"X-Forwarded-For\"] = fwd.join(\", \");\n headers[\"X-Forwarded-Host\"] = host.host;\n headers[\"X-Forwarded-Protocol\"] = host.protocol;\n\n if ((request as any)._proxy) {\n // Proxying and wrapping\n\n // Delete cache headers\n delete headers[\"if-modified-since\"];\n delete headers[\"if-none-match\"];\n delete headers[\"if-unmodified-since\"];\n delete headers[\"if-none-match\"];\n delete headers[\"if-range\"];\n if (rewriteRequestHeaders) {\n return rewriteRequestHeaders(request, headers);\n }\n }\n return headers;\n },\n async onResponse(req, reply: FastifyReply<RawServerBase>, res) {\n const { isPageContext = false, originalUrl = undefined } =\n (req as RequestExtendedWithProxy)._proxy || {};\n if (isPageContext && originalUrl) {\n // restore url rewrite\n req.raw.url = originalUrl;\n }\n\n if ([301, 302, 303, 307, 308].includes(reply.statusCode)) {\n const location = reply.getHeader(\"location\") as string;\n if (location) {\n const url = new URL(location);\n if (url.host === upstream.host) {\n // rewrite redirect on upstream's host to the proxy host\n url.host = host.host;\n }\n reply.header(\"location\", url);\n if (isPageContext) {\n reply\n .status(200)\n .type(\"application/json\")\n .send(\n JSON.stringify({\n pageContext: {\n _pageId: proxyPageId,\n redirectTo: url,\n },\n })\n );\n } else {\n return reply.send(res);\n }\n }\n }\n\n const { layout, layoutProps } = getLayout(reply);\n if (!layout) {\n return reply.send(res);\n }\n\n const proxy = await streamToString(res);\n\n const pageContextInit: Partial<PageContextProxy> = {\n urlOriginal: req.url,\n layout,\n layoutProps,\n };\n if (isPageContext) {\n // proxySendClient is serialized and sent to client on subsequent navigation.\n Object.assign(pageContextInit, { proxySendClient: proxy });\n } else {\n // proxy is ONLY included server-side to avoid doubling page size\n Object.assign(pageContextInit, { proxy });\n }\n const pageContext = await renderPage(pageContextInit);\n return replyWithPage(reply, pageContext);\n },\n },\n });\n};\n"],"mappings":";AAGA,OAAO,WAAW;AAClB,OAAO,aAAa;AAEpB,OAAO,eAAe;AAOtB,SAAS,kBAAkB;AAQ3B,SAAS,eAAe,QAAmC;AACzD,QAAM,SAAmB,CAAC;AAC1B,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,WAAO,GAAG,QAAQ,CAAC,UAAU,OAAO,KAAK,OAAO,KAAK,KAAK,CAAC,CAAC;AAC5D,WAAO,GAAG,SAAS,CAAC,QAAQ,OAAO,GAAG,CAAC;AACvC,WAAO,GAAG,OAAO,MAAM,QAAQ,OAAO,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC,CAAC;AAAA,EACxE,CAAC;AACH;AAEA,eAAe,cACb,OACA,aAQuB;AACvB,QAAM,EAAE,aAAa,IAAI;AAEzB,MAAI,YAAY,cAAc,CAAC,YAAY,wBAAwB;AACjE,WAAO,MAAM,SAAS,KAAK,YAAY,UAAU;AAAA,EACnD;AAEA,MAAI,CAAC,cAAc;AACjB,WAAO,MAAM,KAAK,GAAG,EAAE,KAAK,WAAW,EAAE,KAAK,WA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AAO,MAAM,KAAK,GAAG;AAAA,YACvB;AAAA,UACF;AAAA,QACF;AAEA,cAAM,EAAE,QAAQ,YAAY,IAAI,UAAU,KAAK;AAC/C,YAAI,CAAC,QAAQ;AACX,iBAAO,MAAM,KAAK,GAAG;AAAA,QACvB;AAEA,cAAMA,SAAQ,MAAM,eAAe,GAAG;AAEtC,cAAM,kBAA6C;AAAA,UACjD,aAAa,IAAI;AAAA,UACjB;AAAA,UACA;AAAA,QACF;AACA,YAAI,eAAe;AAEjB,iBAAO,OAAO,iBAAiB,EAAE,iBAAiBA,OAAM,CAAC;AAAA,QAC3D,OAAO;AAEL,iBAAO,OAAO,iBAAiB,EAAE,OAAAA,OAAM,CAAC;AAAA,QAC1C;AACA,cAAM,cAAc,MAAM,WAAW,eAAe;AACpD,eAAO,cAAc,OAAO,WAAW;AAAA,MACzC;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":["proxy"]}
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["// Note that this file isn't processed by Vite, see https://github.com/brillout/vite-plugin-ssr/issues/562\nimport { FastifyReply, RawServerBase, FastifyPluginAsync } from \"fastify\";\nimport { FastifyRequest, RequestGenericInterface } from \"fastify/types/request\";\nimport proxy from \"@fastify/http-proxy\";\nimport accepts from \"@fastify/accepts\";\nimport forwarded from \"@fastify/forwarded\";\nimport { Writable } from \"stream\";\nimport { IncomingHttpHeaders, IncomingMessage } from \"http\";\nimport {\n Http2ServerRequest,\n IncomingHttpHeaders as Http2IncomingHttpHeaders,\n} from \"http2\";\nimport { renderPage } from \"vite-plugin-ssr/server\";\nimport { AugmentMe } from \"@alignable/bifrost\";\n\ntype RequestExtendedWithProxy = FastifyRequest<\n RequestGenericInterface,\n RawServerBase\n> & { _proxy?: { isPageContext: boolean; originalUrl?: string } };\n\nfunction streamToString(stream: Writable): Promise<string> {\n const chunks: Buffer[] = [];\n return new Promise((resolve, reject) => {\n stream.on(\"data\", (chunk) => chunks.push(Buffer.from(chunk)));\n stream.on(\"error\", (err) => reject(err));\n stream.on(\"end\", () => resolve(Buffer.concat(chunks).toString(\"utf8\")));\n });\n}\n\nasync function replyWithPage(\n reply: FastifyReply<RawServerBase>,\n pageContext: Awaited<\n ReturnType<\n typeof renderPage<\n { redirectTo?: string; isClientSideNavigation?: boolean },\n { urlOriginal: string }\n >\n >\n >\n): Promise<FastifyReply> {\n const { httpResponse } = pageContext;\n\n if (pageContext.redirectTo && !pageContext.isClientSideNavigation) {\n return reply.redirect(307, pageContext.redirectTo);\n }\n\n if (!httpResponse) {\n return reply.code(404).type(\"text/html\").send(\"Not Found\");\n }\n\n const { body, statusCode, headers } = httpResponse;\n return reply\n .status(statusCode)\n .headers(Object.fromEntries(headers))\n .send(body);\n}\n\nconst proxyPageId = \"/proxy/pages\";\n\ninterface ViteProxyPluginOptions {\n upstream: URL;\n host: URL;\n buildPageContextInit?: (\n req: FastifyRequest\n ) => Promise<AugmentMe.PageContextInit>;\n getLayout: (reply: FastifyReply<RawServerBase>) => {\n layout: string;\n layoutProps: AugmentMe.LayoutProps;\n };\n /// Use to signal to legacy backend to return special results (eg. remove navbar etc)\n rewriteRequestHeaders?: (\n req: Http2ServerRequest | IncomingMessage,\n headers: Http2IncomingHttpHeaders | IncomingHttpHeaders\n ) => Http2IncomingHttpHeaders | IncomingHttpHeaders;\n}\n/**\n * Fastify plugin that wraps @fasitfy/http-proxy to proxy Rails/Turbolinks server into a Vite-Plugin-SSR site.\n */\nexport const viteProxyPlugin: FastifyPluginAsync<\n ViteProxyPluginOptions\n> = async (\n fastify,\n { upstream, host, buildPageContextInit, rewriteRequestHeaders, getLayout }\n) => {\n await fastify.register(accepts);\n await fastify.register(proxy, {\n upstream: upstream.href,\n async preHandler(req, reply) {\n if (req.method === \"GET\" && req.accepts().type([\"html\"]) === \"html\") {\n const pageContextInit = {\n urlOriginal: req.url,\n ...(buildPageContextInit ? await buildPageContextInit(req) : {}),\n };\n\n const pageContext = await renderPage<\n { _pageId: string },\n typeof pageContextInit\n >(pageContextInit);\n\n const proxy = pageContext._pageId === proxyPageId;\n const noRouteMatched =\n (pageContext as any).is404 && !pageContext.errorWhileRendering; // we hit no page, but NOT because of an error\n\n if (noRouteMatched) {\n req.log.info(\"bifrost: no route match, naked proxy to backend\");\n // Naked proxy\n return;\n } else if (!proxy) {\n req.log.info(`bifrost: rendering page ${pageContext._pageId}`);\n return replyWithPage(reply, pageContext);\n } else {\n req.log.info(`bifrost: proxy route matched, proxying to backend`);\n // pageContext.json is added on client navigations to indicate we are returning just json for the client router\n // we have to remove it before proxying though.\n (req as RequestExtendedWithProxy)._proxy = {\n isPageContext: req.raw.url!.includes(\"/index.pageContext.json\"),\n originalUrl: req.raw.url,\n };\n (req.raw as any)._proxy = true;\n req.raw.url = req.raw.url!.replace(\"/index.pageContext.json\", \"\");\n }\n }\n },\n replyOptions: {\n rewriteRequestHeaders(request, headers) {\n const fwd = forwarded(request as IncomingMessage).reverse();\n // fwd.push(request.ip); TODO: not sure if this is needed\n headers[\"X-Forwarded-For\"] = fwd.join(\", \");\n headers[\"X-Forwarded-Host\"] = host.host;\n headers[\"X-Forwarded-Protocol\"] = host.protocol;\n\n if ((request as any)._proxy) {\n // Proxying and wrapping\n\n // Delete cache headers\n delete headers[\"if-modified-since\"];\n delete headers[\"if-none-match\"];\n delete headers[\"if-unmodified-since\"];\n delete headers[\"if-none-match\"];\n delete headers[\"if-range\"];\n if (rewriteRequestHeaders) {\n return rewriteRequestHeaders(request, headers);\n }\n }\n return headers;\n },\n async onResponse(req, reply: FastifyReply<RawServerBase>, res) {\n const { isPageContext = false, originalUrl = undefined } =\n (req as RequestExtendedWithProxy)._proxy || {};\n if (isPageContext && originalUrl) {\n // restore url rewrite\n req.raw.url = originalUrl;\n }\n\n if ([301, 302, 303, 307, 308].includes(reply.statusCode)) {\n const location = reply.getHeader(\"location\") as string;\n if (location) {\n const url = new URL(location);\n if (url.host === upstream.host) {\n // rewrite redirect on upstream's host to the proxy host\n url.host = host.host;\n }\n reply.header(\"location\", url);\n if (isPageContext) {\n return reply\n .status(200)\n .type(\"application/json\")\n .send(\n JSON.stringify({\n _pageId: proxyPageId,\n redirectTo: url,\n })\n );\n } else {\n return reply.send(res);\n }\n }\n }\n\n const { layout, layoutProps } = getLayout(reply);\n if (!layout) {\n return reply.send(res);\n }\n\n const html = await streamToString(res);\n\n const pageContextInit = {\n urlOriginal: req.url,\n // Nest into fromProxy to avoid triggering pageContextInitHasClientData which forces restorationVisit to refetch pageContext\n // Ideally we would just set restorationVisit onBeforeRender to no-op\n // https://github.com/brillout/vite-plugin-ssr/discussions/1075#discussioncomment-6758711\n fromProxy: {\n layout,\n layoutProps,\n html,\n },\n };\n const pageContext = await renderPage(pageContextInit);\n return replyWithPage(reply, pageContext);\n },\n },\n });\n};\n"],"mappings":";AAGA,OAAO,WAAW;AAClB,OAAO,aAAa;AACpB,OAAO,eAAe;AAOtB,SAAS,kBAAkB;AAQ3B,SAAS,eAAe,QAAmC;AACzD,QAAM,SAAmB,CAAC;AAC1B,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,WAAO,GAAG,QAAQ,CAAC,UAAU,OAAO,KAAK,OAAO,KAAK,KAAK,CAAC,CAAC;AAC5D,WAAO,GAAG,SAAS,CAAC,QAAQ,OAAO,GAAG,CAAC;AACvC,WAAO,GAAG,OAAO,MAAM,QAAQ,OAAO,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC,CAAC;AAAA,EACxE,CAAC;AACH;AAEA,eAAe,cACb,OACA,aAQuB;AACvB,QAAM,EAAE,aAAa,IAAI;AAEzB,MAAI,YAAY,cAAc,CAAC,YAAY,wBAAwB;AACjE,WAAO,MAAM,SAAS,KAAK,YAAY,UAAU;AAAA,EACnD;AAEA,MAAI,CAAC,cAAc;AACjB,WAAO,MAAM,KAAK,GAAG,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW;AAAA,EAC3D;AAEA,QAAM,EAAE,MAAM,YAAY,QAAQ,IAAI;AACtC,SAAO,MACJ,OAAO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;AAAA;AAAA,UAIjB,WAAW;AAAA,YACT;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AACA,cAAM,cAAc,MAAM,WAAW,eAAe;AACpD,eAAO,cAAc,OAAO,WAAW;AAAA,MACzC;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":["proxy"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alignable/bifrost-fastify",
3
3
  "repository": "https://github.com/Alignable/bifrost.git",
4
- "version": "0.0.22",
4
+ "version": "0.0.23",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -18,9 +18,9 @@
18
18
  "vite": "^4.0.3"
19
19
  },
20
20
  "peerDependencies": {
21
- "@alignable/bifrost": "0.0.22",
21
+ "@alignable/bifrost": "0.0.23",
22
22
  "fastify": "^4.9.2",
23
- "vite-plugin-ssr": "0.4.131-commit-35ca471f7"
23
+ "vite-plugin-ssr": "0.4.135"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/connect": "^3.4.35",