rasengan 1.0.0-beta.27 → 1.0.0-beta.28

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.
@@ -34,128 +34,142 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
- if (ar || !(i in from)) {
40
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
- ar[i] = from[i];
42
- }
43
- }
44
- return to.concat(ar || Array.prototype.slice.call(from));
45
- };
46
- import fs from "node:fs/promises";
47
- import fsSync from "node:fs";
48
- import path, { join, dirname } from "node:path";
49
- import { fileURLToPath } from "node:url";
50
- import { createStaticHandler, createStaticRouter, } from "react-router-dom/server.js";
37
+ // import fs from "node:fs/promises";
38
+ // import fsSync from "node:fs";
39
+ // import path, { join } from "node:path";
40
+ // import {
41
+ // StaticHandlerContext,
42
+ // createStaticHandler,
43
+ // createStaticRouter,
44
+ // } from "react-router-dom/server.js";
45
+ // @ts-ignore
46
+ // import { createFetchRequest } from "rasengan";
51
47
  // @ts-ignore
52
- import { createFetchRequest } from "rasengan";
48
+ import { handleRequest } from "rasengan";
49
+ // export default async (req: Request, context: Context) => {
50
+ // try {
51
+ // // Get URL
52
+ // const url = req.url;
53
+ // const host = req.headers.get("host")
54
+ // // Get app path
55
+ // // const appPath = join(__dirname, "..");
56
+ // const appPath = process.cwd();
57
+ // // ! Robots Fix
58
+ // if (url === "/robots.txt") {
59
+ // // Check if robots.txt exists using fs
60
+ // // If it does, return it
61
+ // try {
62
+ // await fs.access(path.resolve(join(appPath, "dist/client/robots.txt")));
63
+ // return new Response(path.resolve(join(appPath, "dist/client/robots.txt")))
64
+ // } catch (err: any) {
65
+ // return new Response(`
66
+ // user-agent: *
67
+ // disallow: /downloads/
68
+ // disallow: /private/
69
+ // allow: /
70
+ // user-agent: magicsearchbot
71
+ // disallow: /uploads/
72
+ // `)
73
+ // }
74
+ // }
75
+ // // ! Sitemap Fix
76
+ // if (url === "/sitemap.xml") {
77
+ // return new Response(path.resolve(join(appPath, "dist/client/sitemap.xml")))
78
+ // }
79
+ // // ! Manifest Fix
80
+ // if (url === "/manifest.json") {
81
+ // return new Response(path.resolve(join(appPath, "dist/client/manifest.json")))
82
+ // }
83
+ // // ! Handle assets
84
+ // if (url.includes("/assets")) {
85
+ // // get segments from /assets to the end
86
+ // const segments = url.split("/");
87
+ // const segmentsWithoutOrigin = [...segments];
88
+ // for (let segment of segments) {
89
+ // if (segment === "assets") {
90
+ // break;
91
+ // }
92
+ // segmentsWithoutOrigin.shift();
93
+ // }
94
+ // // replace assets by client/assets
95
+ // const filePath = join(appPath, "dist/client", segmentsWithoutOrigin.join("/"));
96
+ // const file = await fs.readFile(filePath, "utf-8");
97
+ // return new Response(file, {
98
+ // headers: {
99
+ // "Content-Type": url.endsWith(".js") ? "text/javascript" : "text/css",
100
+ // "Cache-Control": "max-age=31536000",
101
+ // },
102
+ // });
103
+ // }
104
+ // // Template html
105
+ // let templateHtml = "";
106
+ // // Always read fresh template in development
107
+ // const serverFilePath = join(appPath, "dist/server/entry-server.js");
108
+ // const bootstrapDirPath = join(appPath, "dist/client/assets")
109
+ // // Read the entry sever file
110
+ // let entry = await import(serverFilePath);
111
+ // // replace bootstrap script with compiled scripts
112
+ // let bootstrap =
113
+ // "/assets/" +
114
+ // fsSync
115
+ // .readdirSync(bootstrapDirPath)
116
+ // .filter((fn) => fn.includes("entry-client") && fn.endsWith(".js"))[0];
117
+ // // replace styles with compiled styles
118
+ // let styles =
119
+ // "/assets/" +
120
+ // fsSync
121
+ // .readdirSync(join(appPath, "dist/client/assets"))
122
+ // .filter((fn) => fn.includes("entry-client") && fn.endsWith(".css"))[0];
123
+ // // Extract render and staticRoutes from entry
124
+ // const { render, staticRoutes, loadTemplateHtml } = entry;
125
+ // // Create static handler
126
+ // let handler = createStaticHandler(staticRoutes);
127
+ // // Create fetch request for static routing
128
+ // // @ts-ignore
129
+ // let fetchRequest = createFetchRequest(req, host);
130
+ // let context = await handler.query(fetchRequest);
131
+ // // Handle redirects
132
+ // const status = (context as Response).status;
133
+ // if (status === 302) {
134
+ // const redirect = (context as Response).headers.get("Location");
135
+ // if (redirect) {
136
+ // return Response.redirect(redirect);
137
+ // }
138
+ // }
139
+ // // Helmet context
140
+ // const helmetContext = {} as { helmet: any };
141
+ // // Create static router
142
+ // let router = createStaticRouter(
143
+ // handler.dataRoutes,
144
+ // context as StaticHandlerContext
145
+ // );
146
+ // const rendered = await render(router, context, helmetContext);
147
+ // // Load template html
148
+ // if (!templateHtml) {
149
+ // templateHtml = loadTemplateHtml(helmetContext, bootstrap, styles);
150
+ // }
151
+ // // Replacing the app-html placeholder with the rendered html
152
+ // let html = templateHtml.replace(`rasengan-body-app`, rendered.html ?? "");
153
+ // // Send the rendered html page
154
+ // return new Response(html, {
155
+ // status: 200,
156
+ // headers: {
157
+ // "Content-Type": "text/html",
158
+ // "Cache-Control": "max-age=31536000",
159
+ // },
160
+ // });
161
+ // } catch (e: any) {
162
+ // console.log(e.stack);
163
+ // return new Response(e.stack, {
164
+ // status: 500,
165
+ // });
166
+ // }
167
+ // }
53
168
  export default (function (req, context) { return __awaiter(void 0, void 0, void 0, function () {
54
- var __filename, __dirname, url, host, appPath, err_1, segments, segmentsWithoutOrigin, _i, segments_1, segment, filePath, file, templateHtml, serverFilePath, bootstrapDirPath, entry, bootstrap, styles, render, staticRoutes, loadTemplateHtml, handler, fetchRequest, context_1, status_1, redirect, helmetContext, router, rendered, html, e_1;
55
- var _a;
56
- return __generator(this, function (_b) {
57
- switch (_b.label) {
58
- case 0:
59
- __filename = fileURLToPath(import.meta.url);
60
- __dirname = dirname(__filename);
61
- _b.label = 1;
62
- case 1:
63
- _b.trys.push([1, 11, , 12]);
64
- url = req.url;
65
- host = req.headers.get("host");
66
- appPath = process.cwd();
67
- if (!(url === "/robots.txt")) return [3 /*break*/, 5];
68
- _b.label = 2;
69
- case 2:
70
- _b.trys.push([2, 4, , 5]);
71
- return [4 /*yield*/, fs.access(path.resolve(join(appPath, "dist/client/robots.txt")))];
72
- case 3:
73
- _b.sent();
74
- return [2 /*return*/, new Response(path.resolve(join(appPath, "dist/client/robots.txt")))];
75
- case 4:
76
- err_1 = _b.sent();
77
- return [2 /*return*/, new Response("\n user-agent: *\n disallow: /downloads/\n disallow: /private/\n allow: /\n \n user-agent: magicsearchbot\n disallow: /uploads/\n ")];
78
- case 5:
79
- // ! Sitemap Fix
80
- if (url === "/sitemap.xml") {
81
- return [2 /*return*/, new Response(path.resolve(join(appPath, "dist/client/sitemap.xml")))];
82
- }
83
- // ! Manifest Fix
84
- if (url === "/manifest.json") {
85
- return [2 /*return*/, new Response(path.resolve(join(appPath, "dist/client/manifest.json")))];
86
- }
87
- if (!url.includes("/assets")) return [3 /*break*/, 7];
88
- segments = url.split("/");
89
- segmentsWithoutOrigin = __spreadArray([], segments, true);
90
- for (_i = 0, segments_1 = segments; _i < segments_1.length; _i++) {
91
- segment = segments_1[_i];
92
- if (segment === "assets") {
93
- break;
94
- }
95
- segmentsWithoutOrigin.shift();
96
- }
97
- filePath = join(appPath, "dist/client", segmentsWithoutOrigin.join("/"));
98
- return [4 /*yield*/, fs.readFile(filePath, "utf-8")];
99
- case 6:
100
- file = _b.sent();
101
- return [2 /*return*/, new Response(file, {
102
- headers: {
103
- "Content-Type": url.endsWith(".js") ? "text/javascript" : "text/css",
104
- },
105
- })];
106
- case 7:
107
- templateHtml = "";
108
- serverFilePath = join(appPath, "dist/server/entry-server.js");
109
- bootstrapDirPath = join(appPath, "dist/client/assets");
110
- return [4 /*yield*/, import(serverFilePath)];
111
- case 8:
112
- entry = _b.sent();
113
- bootstrap = "/assets/" +
114
- fsSync
115
- .readdirSync(bootstrapDirPath)
116
- .filter(function (fn) { return fn.includes("entry-client") && fn.endsWith(".js"); })[0];
117
- styles = "/assets/" +
118
- fsSync
119
- .readdirSync(join(appPath, "dist/client/assets"))
120
- .filter(function (fn) { return fn.includes("entry-client") && fn.endsWith(".css"); })[0];
121
- render = entry.render, staticRoutes = entry.staticRoutes, loadTemplateHtml = entry.loadTemplateHtml;
122
- handler = createStaticHandler(staticRoutes);
123
- fetchRequest = createFetchRequest(req, host);
124
- return [4 /*yield*/, handler.query(fetchRequest)];
125
- case 9:
126
- context_1 = _b.sent();
127
- status_1 = context_1.status;
128
- if (status_1 === 302) {
129
- redirect = context_1.headers.get("Location");
130
- if (redirect) {
131
- return [2 /*return*/, Response.redirect(redirect)];
132
- }
133
- }
134
- helmetContext = {};
135
- router = createStaticRouter(handler.dataRoutes, context_1);
136
- return [4 /*yield*/, render(router, context_1, helmetContext)];
137
- case 10:
138
- rendered = _b.sent();
139
- // Load template html
140
- if (!templateHtml) {
141
- templateHtml = loadTemplateHtml(helmetContext, bootstrap, styles);
142
- }
143
- html = templateHtml.replace("rasengan-body-app", (_a = rendered.html) !== null && _a !== void 0 ? _a : "");
144
- // Send the rendered html page
145
- return [2 /*return*/, new Response(html, {
146
- status: 200,
147
- headers: {
148
- "Content-Type": "text/html",
149
- "Cache-Control": "max-age=31536000",
150
- },
151
- })];
152
- case 11:
153
- e_1 = _b.sent();
154
- console.log(e_1.stack);
155
- return [2 /*return*/, new Response(e_1.stack, {
156
- status: 500,
157
- })];
158
- case 12: return [2 /*return*/];
169
+ return __generator(this, function (_a) {
170
+ switch (_a.label) {
171
+ case 0: return [4 /*yield*/, handleRequest(req)];
172
+ case 1: return [2 /*return*/, _a.sent()];
159
173
  }
160
174
  });
161
175
  }); });
@@ -34,108 +34,141 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
- import fs from "node:fs/promises";
38
- import fsSync from "node:fs";
39
- import path, { join, dirname } from "node:path";
40
- import { fileURLToPath } from "node:url";
41
- import { createStaticHandler, createStaticRouter, } from "react-router-dom/server.js";
37
+ // import fs from "node:fs/promises";
38
+ // import fsSync from "node:fs";
39
+ // import path, { join, dirname } from "node:path";
40
+ // import { fileURLToPath } from "node:url";
41
+ // import {
42
+ // StaticHandlerContext,
43
+ // createStaticHandler,
44
+ // createStaticRouter,
45
+ // } from "react-router-dom/server.js";
42
46
  // @ts-ignore
43
- import { createFetchRequest } from "rasengan";
47
+ // import { createFetchRequest } from "rasengan";
48
+ import { handleRequest } from "rasengan";
44
49
  // Create server for production only
50
+ // export default async function handler(req: VercelRequest, res: VercelResponse) {
51
+ // // @ts-ignore
52
+ // const __filename = fileURLToPath(import.meta.url);
53
+ // const __dirname = dirname(__filename);
54
+ // console.log({ __dirname })
55
+ // try {
56
+ // // Get URL
57
+ // const url = req.url;
58
+ // const host = req.headers.host;
59
+ // // Get app path
60
+ // const appPath = process.cwd();
61
+ // // ! Robots Fix
62
+ // if (url === "/robots.txt") {
63
+ // // Check if robots.txt exists using fs
64
+ // // If it does, return it
65
+ // try {
66
+ // await fs.access(path.resolve(join(appPath, "dist/client/robots.txt")));
67
+ // return res.send(path.resolve(join(appPath, "dist/client/robots.txt")));
68
+ // } catch (err: any) {
69
+ // return res.send(`
70
+ // user-agent: *
71
+ // disallow: /downloads/
72
+ // disallow: /private/
73
+ // allow: /
74
+ // user-agent: magicsearchbot
75
+ // disallow: /uploads/
76
+ // `);
77
+ // }
78
+ // }
79
+ // // ! Sitemap Fix
80
+ // if (url === "/sitemap.xml") {
81
+ // return res.send(path.resolve(join(appPath, "dist/client/sitemap.xml")));
82
+ // }
83
+ // // ! Manifest Fix
84
+ // if (url === "/manifest.json") {
85
+ // return res.send(path.resolve(join(appPath, "dist/client/manifest.json")));
86
+ // }
87
+ // // ! Handle assets
88
+ // if (url.includes("/assets")) {
89
+ // // get segments from /assets to the end
90
+ // const segments = url.split("/");
91
+ // const segmentsWithoutOrigin = [...segments];
92
+ // for (let segment of segments) {
93
+ // if (segment === "assets") {
94
+ // break;
95
+ // }
96
+ // segmentsWithoutOrigin.shift();
97
+ // }
98
+ // // replace assets by client/assets
99
+ // const filePath = join(appPath, "dist/client", segmentsWithoutOrigin.join("/"));
100
+ // const file = await fs.readFile(filePath, "utf-8");
101
+ // return new Response(file, {
102
+ // headers: {
103
+ // "Content-Type": url.endsWith(".js") ? "text/javascript" : "text/css",
104
+ // "Cache-Control": "max-age=31536000",
105
+ // },
106
+ // });
107
+ // }
108
+ // // Template html
109
+ // let templateHtml = "";
110
+ // // Always read fresh template in development
111
+ // const serverFilePath = join(appPath, "dist/server/entry-server.js");
112
+ // const bootstrapDirPath = join(appPath, "dist/client/assets")
113
+ // // Read the entry sever file
114
+ // let entry = await import(serverFilePath);
115
+ // // replace bootstrap script with compiled scripts
116
+ // let bootstrap =
117
+ // "/assets/" +
118
+ // fsSync
119
+ // .readdirSync(bootstrapDirPath)
120
+ // .filter((fn) => fn.includes("entry-client") && fn.endsWith(".js"))[0];
121
+ // // replace styles with compiled styles
122
+ // let styles =
123
+ // "/assets/" +
124
+ // fsSync
125
+ // .readdirSync(join(appPath, "dist/client/assets"))
126
+ // .filter((fn) => fn.includes("entry-client") && fn.endsWith(".css"))[0];
127
+ // // Extract render and staticRoutes from entry
128
+ // const { render, staticRoutes, loadTemplateHtml } = entry;
129
+ // // Create static handler
130
+ // let handler = createStaticHandler(staticRoutes);
131
+ // // Create fetch request for static routing
132
+ // // @ts-ignore
133
+ // let fetchRequest = createFetchRequest(req, host);
134
+ // let context = await handler.query(fetchRequest);
135
+ // // Handle redirects
136
+ // const status = (context as Response).status;
137
+ // if (status === 302) {
138
+ // const redirect = (context as Response).headers.get("Location");
139
+ // if (redirect) return res.redirect(redirect);
140
+ // }
141
+ // // Helmet context
142
+ // const helmetContext = {} as { helmet: any };
143
+ // // Create static router
144
+ // let router = createStaticRouter(
145
+ // handler.dataRoutes,
146
+ // context as StaticHandlerContext
147
+ // );
148
+ // const rendered = await render(router, context, helmetContext);
149
+ // // Load template html
150
+ // if (!templateHtml) {
151
+ // templateHtml = loadTemplateHtml(helmetContext, bootstrap, styles);
152
+ // }
153
+ // // Replacing the app-html placeholder with the rendered html
154
+ // let html = templateHtml.replace(`rasengan-body-app`, rendered.html ?? "");
155
+ // // Send the rendered html page
156
+ // return res
157
+ // .status(200)
158
+ // .setHeader("Content-Type", "text/html")
159
+ // .setHeader("Cache-Control", "max-age=31536000")
160
+ // .end(html);
161
+ // } catch (e: any) {
162
+ // console.log(e.stack);
163
+ // res.status(500).end(e.stack);
164
+ // }
165
+ // }
45
166
  export default function handler(req, res) {
46
- var _a;
47
167
  return __awaiter(this, void 0, void 0, function () {
48
- var __filename, __dirname, url, host, appPath, err_1, file, templateHtml, serverFilePath, bootstrapDirPath, entry, bootstrap, styles, render, staticRoutes, loadTemplateHtml, handler_1, fetchRequest, context, status_1, redirect, helmetContext, router, rendered, html, e_1;
49
- return __generator(this, function (_b) {
50
- switch (_b.label) {
51
- case 0:
52
- __filename = fileURLToPath(import.meta.url);
53
- __dirname = dirname(__filename);
54
- console.log({ __dirname: __dirname });
55
- _b.label = 1;
56
- case 1:
57
- _b.trys.push([1, 11, , 12]);
58
- url = req.url;
59
- host = req.headers.host;
60
- appPath = process.cwd();
61
- if (!(url === "/robots.txt")) return [3 /*break*/, 5];
62
- _b.label = 2;
63
- case 2:
64
- _b.trys.push([2, 4, , 5]);
65
- return [4 /*yield*/, fs.access(path.resolve(join(appPath, "dist/client/robots.txt")))];
66
- case 3:
67
- _b.sent();
68
- return [2 /*return*/, res.send(path.resolve(join(appPath, "dist/client/robots.txt")))];
69
- case 4:
70
- err_1 = _b.sent();
71
- return [2 /*return*/, res.send("\n user-agent: *\n disallow: /downloads/\n disallow: /private/\n allow: /\n \n user-agent: magicsearchbot\n disallow: /uploads/\n ")];
72
- case 5:
73
- // ! Sitemap Fix
74
- if (url === "/sitemap.xml") {
75
- return [2 /*return*/, res.send(path.resolve(join(appPath, "dist/client/sitemap.xml")))];
76
- }
77
- // ! Manifest Fix
78
- if (url === "/manifest.json") {
79
- return [2 /*return*/, res.send(path.resolve(join(appPath, "dist/client/manifest.json")))];
80
- }
81
- if (!(url.endsWith(".js") || url.endsWith(".css"))) return [3 /*break*/, 7];
82
- return [4 /*yield*/, fs.readFile(url, "utf-8")];
83
- case 6:
84
- file = _b.sent();
85
- return [2 /*return*/, new Response(file, {
86
- headers: {
87
- "Content-Type": url.endsWith(".js") ? "text/javascript" : "text/css",
88
- },
89
- })];
90
- case 7:
91
- templateHtml = "";
92
- serverFilePath = join(appPath, "dist/server/entry-server.js");
93
- bootstrapDirPath = join(appPath, "dist/client/assets");
94
- return [4 /*yield*/, import(serverFilePath)];
95
- case 8:
96
- entry = _b.sent();
97
- bootstrap = "/assets/" +
98
- fsSync
99
- .readdirSync(bootstrapDirPath)
100
- .filter(function (fn) { return fn.includes("entry-client") && fn.endsWith(".js"); })[0];
101
- styles = "/assets/" +
102
- fsSync
103
- .readdirSync(join(appPath, "dist/client/assets"))
104
- .filter(function (fn) { return fn.includes("entry-client") && fn.endsWith(".css"); })[0];
105
- render = entry.render, staticRoutes = entry.staticRoutes, loadTemplateHtml = entry.loadTemplateHtml;
106
- handler_1 = createStaticHandler(staticRoutes);
107
- fetchRequest = createFetchRequest(req, host);
108
- return [4 /*yield*/, handler_1.query(fetchRequest)];
109
- case 9:
110
- context = _b.sent();
111
- status_1 = context.status;
112
- if (status_1 === 302) {
113
- redirect = context.headers.get("Location");
114
- if (redirect)
115
- return [2 /*return*/, res.redirect(redirect)];
116
- }
117
- helmetContext = {};
118
- router = createStaticRouter(handler_1.dataRoutes, context);
119
- return [4 /*yield*/, render(router, context, helmetContext)];
120
- case 10:
121
- rendered = _b.sent();
122
- // Load template html
123
- if (!templateHtml) {
124
- templateHtml = loadTemplateHtml(helmetContext, bootstrap, styles);
125
- }
126
- html = templateHtml.replace("rasengan-body-app", (_a = rendered.html) !== null && _a !== void 0 ? _a : "");
127
- // Send the rendered html page
128
- return [2 /*return*/, res
129
- .status(200)
130
- .setHeader("Content-Type", "text/html")
131
- .setHeader("Cache-Control", "max-age=31536000")
132
- .end(html)];
133
- case 11:
134
- e_1 = _b.sent();
135
- console.log(e_1.stack);
136
- res.status(500).end(e_1.stack);
137
- return [3 /*break*/, 12];
138
- case 12: return [2 /*return*/];
168
+ return __generator(this, function (_a) {
169
+ switch (_a.label) {
170
+ case 0: return [4 /*yield*/, handleRequest(req, res)];
171
+ case 1: return [2 /*return*/, _a.sent()];
139
172
  }
140
173
  });
141
174
  });
@@ -34,64 +34,120 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
+ if (ar || !(i in from)) {
40
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
+ ar[i] = from[i];
42
+ }
43
+ }
44
+ return to.concat(ar || Array.prototype.slice.call(from));
45
+ };
37
46
  import fs from "node:fs/promises";
38
47
  import fsSync from "node:fs";
39
- import path, { dirname, join } from "node:path";
48
+ import path, { join } from "node:path";
40
49
  import { createStaticHandler, createStaticRouter, } from "react-router-dom/server.js";
41
50
  // @ts-ignore
42
51
  import { createFetchRequest } from "rasengan";
43
- import { fileURLToPath } from "node:url";
44
52
  // Create server for production only
45
53
  export default function handleRequest(req, res) {
46
54
  var _a;
47
55
  return __awaiter(this, void 0, void 0, function () {
48
- var __filename, __dirname, url, host, appPath, err_1, templateHtml, serverFilePath, bootstrapDirPath, entry, bootstrap, styles, render, staticRoutes, loadTemplateHtml, handler, fetchRequest, context, status_1, redirect, helmetContext, router, rendered, html, e_1;
56
+ var url, host, appPath, err_1, segments, segmentsWithoutOrigin, _i, segments_1, segment, filePath, file, file, templateHtml, serverFilePath, bootstrapDirPath, entry, bootstrap, styles, render, staticRoutes, loadTemplateHtml, handler, fetchRequest, context, status_1, redirect, helmetContext, router, rendered, html, e_1;
49
57
  return __generator(this, function (_b) {
50
58
  switch (_b.label) {
51
59
  case 0:
52
- __filename = fileURLToPath(import.meta.url);
53
- __dirname = dirname(__filename);
54
- console.log({
55
- cwd: process.cwd(),
56
- __dirname: __dirname
57
- });
58
- // read dir
59
- console.log({
60
- readdir: fsSync.readdirSync(__dirname),
61
- readdir2: fsSync.readdirSync(join(process.cwd(), "..")),
62
- readdir3: fsSync.readdirSync(join(process.cwd(), "..", "..")),
63
- });
60
+ _b.trys.push([0, 12, , 13]);
61
+ url = req.url;
62
+ host = req.headers.host ? req.headers.host : req.headers.get("host") || "";
63
+ appPath = process.cwd();
64
+ if (!(url === "/robots.txt")) return [3 /*break*/, 4];
64
65
  _b.label = 1;
65
66
  case 1:
66
- _b.trys.push([1, 9, , 10]);
67
- url = req.url;
68
- host = req.headers.host;
69
- appPath = join(__dirname, "..");
70
- if (!(url === "/robots.txt")) return [3 /*break*/, 5];
71
- _b.label = 2;
72
- case 2:
73
- _b.trys.push([2, 4, , 5]);
67
+ _b.trys.push([1, 3, , 4]);
74
68
  return [4 /*yield*/, fs.access(path.resolve(join(appPath, "dist/client/robots.txt")))];
75
- case 3:
69
+ case 2:
76
70
  _b.sent();
77
- return [2 /*return*/, res.send(path.resolve(join(appPath, "dist/client/robots.txt")))];
78
- case 4:
71
+ if (res)
72
+ return [2 /*return*/, res.send(path.resolve(join(appPath, "dist/client/robots.txt")))];
73
+ return [2 /*return*/, new Response(path.resolve(join(appPath, "dist/client/robots.txt")), {
74
+ status: 200
75
+ })];
76
+ case 3:
79
77
  err_1 = _b.sent();
80
- return [2 /*return*/, res.send("\n user-agent: *\n disallow: /downloads/\n disallow: /private/\n allow: /\n \n user-agent: magicsearchbot\n disallow: /uploads/\n ")];
81
- case 5:
78
+ if (res)
79
+ return [2 /*return*/, res.send("\n user-agent: *\n disallow: /downloads/\n disallow: /private/\n allow: /\n \n user-agent: magicsearchbot\n disallow: /uploads/\n ")];
80
+ return [2 /*return*/, new Response("\n user-agent: *\n disallow: /downloads/\n disallow: /private/\n allow: /\n \n user-agent: magicsearchbot\n disallow: /uploads/\n ", {
81
+ status: 200
82
+ })];
83
+ case 4:
82
84
  // ! Sitemap Fix
83
85
  if (url === "/sitemap.xml") {
84
- return [2 /*return*/, res.send(path.resolve(join(appPath, "dist/client/sitemap.xml")))];
86
+ if (res)
87
+ return [2 /*return*/, res.send(path.resolve(join(appPath, "dist/client/sitemap.xml")))];
88
+ return [2 /*return*/, new Response(path.resolve(join(appPath, "dist/client/sitemap.xml")), {
89
+ status: 200
90
+ })];
85
91
  }
86
92
  // ! Manifest Fix
87
93
  if (url === "/manifest.json") {
88
- return [2 /*return*/, res.send(path.resolve(join(appPath, "dist/client/manifest.json")))];
94
+ if (res)
95
+ return [2 /*return*/, res.send(path.resolve(join(appPath, "dist/client/manifest.json")))];
96
+ return [2 /*return*/, new Response(path.resolve(join(appPath, "dist/client/manifest.json")), {
97
+ status: 200
98
+ })];
99
+ }
100
+ if (!url.includes("/assets")) return [3 /*break*/, 6];
101
+ segments = url.split("/");
102
+ segmentsWithoutOrigin = __spreadArray([], segments, true);
103
+ for (_i = 0, segments_1 = segments; _i < segments_1.length; _i++) {
104
+ segment = segments_1[_i];
105
+ if (segment === "assets") {
106
+ break;
107
+ }
108
+ segmentsWithoutOrigin.shift();
109
+ }
110
+ filePath = join(appPath, "dist/client", segmentsWithoutOrigin.join("/"));
111
+ return [4 /*yield*/, fs.readFile(filePath, "utf-8")];
112
+ case 5:
113
+ file = _b.sent();
114
+ if (res) {
115
+ return [2 /*return*/, res
116
+ .status(200)
117
+ .setHeader("Content-Type", url.endsWith(".js") ? "text/javascript" : "text/css")
118
+ .setHeader("Cache-Control", "max-age=31536000")
119
+ .end(file)];
89
120
  }
121
+ return [2 /*return*/, new Response(file, {
122
+ headers: {
123
+ "Content-Type": url.endsWith(".js") ? "text/javascript" : "text/css",
124
+ "Cache-Control": "max-age=31536000",
125
+ },
126
+ })];
127
+ case 6:
128
+ if (!(url.endsWith(".js") || url.endsWith(".css"))) return [3 /*break*/, 8];
129
+ return [4 /*yield*/, fs.readFile(url, "utf-8")];
130
+ case 7:
131
+ file = _b.sent();
132
+ if (res) {
133
+ return [2 /*return*/, res
134
+ .status(200)
135
+ .setHeader("Content-Type", url.endsWith(".js") ? "text/javascript" : "text/css")
136
+ .setHeader("Cache-Control", "max-age=31536000")
137
+ .end(file)];
138
+ }
139
+ return [2 /*return*/, new Response(file, {
140
+ headers: {
141
+ "Content-Type": url.endsWith(".js") ? "text/javascript" : "text/css",
142
+ "Cache-Control": "max-age=31536000",
143
+ },
144
+ })];
145
+ case 8:
90
146
  templateHtml = "";
91
147
  serverFilePath = join(appPath, "dist/server/entry-server.js");
92
148
  bootstrapDirPath = join(appPath, "dist/client/assets");
93
149
  return [4 /*yield*/, import(serverFilePath)];
94
- case 6:
150
+ case 9:
95
151
  entry = _b.sent();
96
152
  bootstrap = "/assets/" +
97
153
  fsSync
@@ -105,18 +161,21 @@ export default function handleRequest(req, res) {
105
161
  handler = createStaticHandler(staticRoutes);
106
162
  fetchRequest = createFetchRequest(req, host);
107
163
  return [4 /*yield*/, handler.query(fetchRequest)];
108
- case 7:
164
+ case 10:
109
165
  context = _b.sent();
110
166
  status_1 = context.status;
111
167
  if (status_1 === 302) {
112
168
  redirect = context.headers.get("Location");
113
- if (redirect)
114
- return [2 /*return*/, res.redirect(redirect)];
169
+ if (redirect) {
170
+ if (res)
171
+ return [2 /*return*/, res.redirect(redirect)];
172
+ return [2 /*return*/, Response.redirect(redirect)];
173
+ }
115
174
  }
116
175
  helmetContext = {};
117
176
  router = createStaticRouter(handler.dataRoutes, context);
118
177
  return [4 /*yield*/, render(router, context, helmetContext)];
119
- case 8:
178
+ case 11:
120
179
  rendered = _b.sent();
121
180
  // Load template html
122
181
  if (!templateHtml) {
@@ -138,7 +197,7 @@ export default function handleRequest(req, res) {
138
197
  "Cache-Control": "max-age=31536000",
139
198
  },
140
199
  })];
141
- case 9:
200
+ case 12:
142
201
  e_1 = _b.sent();
143
202
  console.log(e_1.stack);
144
203
  if (res) {
@@ -147,7 +206,7 @@ export default function handleRequest(req, res) {
147
206
  return [2 /*return*/, new Response(e_1.stack, {
148
207
  status: 500,
149
208
  })];
150
- case 10: return [2 /*return*/];
209
+ case 13: return [2 /*return*/];
151
210
  }
152
211
  });
153
212
  });
@@ -1,2 +1,2 @@
1
- declare const _default: (req: Request, context: Context) => Promise<Response>;
1
+ declare const _default: (req: Request, context: Context) => Promise<any>;
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
1
  import type { VercelRequest, VercelResponse } from "@vercel/node";
2
- export default function handler(req: VercelRequest, res: VercelResponse): Promise<Response | VercelResponse>;
2
+ export default function handler(req: VercelRequest, res: VercelResponse): Promise<any>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rasengan",
3
3
  "private": false,
4
- "version": "1.0.0-beta.27",
4
+ "version": "1.0.0-beta.28",
5
5
  "description": "The modern frontend framework for React",
6
6
  "type": "module",
7
7
  "main": "lib/esm/index.js",