rasengan 1.0.0-beta.33 → 1.0.0-beta.35

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.
@@ -55,27 +55,41 @@ import { fileTypeFromBuffer } from "file-type";
55
55
  // // @ts-ignore
56
56
  // import type { Context } from "@netlify/functions"
57
57
  export default (function (req, context) { return __awaiter(void 0, void 0, void 0, function () {
58
- var url, host, appPath, err_1, segments, segmentsWithoutOrigin, _i, segments_1, segment, filePath, file, otherFile, result, mimeType, file, templateHtml, serverFilePath, bootstrapDirPath, entry, bootstrap, styles, render, staticRoutes, loadTemplateHtml, handler, fetchRequest, context_1, status_1, redirect, helmetContext, router, rendered, html, e_1;
58
+ var url, host, appPath, err_1, err_2, segments, segmentsWithoutOrigin, _i, segments_1, segment, newUrl, filePath, file, otherFile, result, mimeType, file, file, res, buffer, mimeType, templateHtml, serverFilePath, bootstrapDirPath, entry, bootstrap, styles, render, staticRoutes, loadTemplateHtml, handler, fetchRequest, context_1, status_1, redirect, helmetContext, router, rendered, html, e_1;
59
59
  var _a;
60
60
  return __generator(this, function (_b) {
61
61
  switch (_b.label) {
62
62
  case 0:
63
- _b.trys.push([0, 14, , 15]);
63
+ _b.trys.push([0, 23, , 24]);
64
64
  url = req.url;
65
65
  host = req.headers.get("host");
66
66
  appPath = process.cwd();
67
- if (!(url === "/robots.txt")) return [3 /*break*/, 4];
67
+ if (!(url === "/favicon.ico")) return [3 /*break*/, 4];
68
68
  _b.label = 1;
69
69
  case 1:
70
70
  _b.trys.push([1, 3, , 4]);
71
- return [4 /*yield*/, fs.access(path.resolve(join(appPath, "dist/client/robots.txt")))];
71
+ return [4 /*yield*/, fs.access(path.resolve(join(appPath, "dist/client/favicon.ico")))];
72
72
  case 2:
73
73
  _b.sent();
74
- return [2 /*return*/, new Response(path.resolve(join(appPath, "dist/client/robots.txt")))];
74
+ return [2 /*return*/, new Response(path.resolve(join(appPath, "dist/client/favicon.ico")))];
75
75
  case 3:
76
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 ")];
77
+ return [2 /*return*/, new Response("", {
78
+ status: 404,
79
+ })];
78
80
  case 4:
81
+ if (!(url === "/robots.txt")) return [3 /*break*/, 8];
82
+ _b.label = 5;
83
+ case 5:
84
+ _b.trys.push([5, 7, , 8]);
85
+ return [4 /*yield*/, fs.access(path.resolve(join(appPath, "dist/client/robots.txt")))];
86
+ case 6:
87
+ _b.sent();
88
+ return [2 /*return*/, new Response(path.resolve(join(appPath, "dist/client/robots.txt")))];
89
+ case 7:
90
+ err_2 = _b.sent();
91
+ 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 ")];
92
+ case 8:
79
93
  // ! Sitemap Fix
80
94
  if (url === "/sitemap.xml") {
81
95
  return [2 /*return*/, new Response(path.resolve(join(appPath, "dist/client/sitemap.xml")))];
@@ -84,7 +98,7 @@ export default (function (req, context) { return __awaiter(void 0, void 0, void
84
98
  if (url === "/manifest.json") {
85
99
  return [2 /*return*/, new Response(path.resolve(join(appPath, "dist/client/manifest.json")))];
86
100
  }
87
- if (!url.includes("/assets")) return [3 /*break*/, 8];
101
+ if (!url.includes("/assets")) return [3 /*break*/, 12];
88
102
  segments = url.split("/");
89
103
  segmentsWithoutOrigin = __spreadArray([], segments, true);
90
104
  for (_i = 0, segments_1 = segments; _i < segments_1.length; _i++) {
@@ -94,9 +108,10 @@ export default (function (req, context) { return __awaiter(void 0, void 0, void
94
108
  }
95
109
  segmentsWithoutOrigin.shift();
96
110
  }
97
- filePath = join(appPath, "dist/client", segmentsWithoutOrigin.join("/"));
111
+ newUrl = segmentsWithoutOrigin.join("/").split("?")[0];
112
+ filePath = join(appPath, "dist/client", newUrl);
98
113
  return [4 /*yield*/, fs.readFile(filePath, "utf-8")];
99
- case 5:
114
+ case 9:
100
115
  file = _b.sent();
101
116
  if (url.endsWith(".js") || url.endsWith(".css")) {
102
117
  return [2 /*return*/, new Response(file, {
@@ -107,10 +122,10 @@ export default (function (req, context) { return __awaiter(void 0, void 0, void
107
122
  })];
108
123
  }
109
124
  return [4 /*yield*/, fs.readFile(filePath)];
110
- case 6:
125
+ case 10:
111
126
  otherFile = _b.sent();
112
127
  return [4 /*yield*/, fileTypeFromBuffer(otherFile)];
113
- case 7:
128
+ case 11:
114
129
  result = _b.sent();
115
130
  mimeType = result ? result.mime : url.endsWith(".svg") ? "image/svg+xml" : "application/octet-stream";
116
131
  return [2 /*return*/, new Response(otherFile, {
@@ -119,10 +134,10 @@ export default (function (req, context) { return __awaiter(void 0, void 0, void
119
134
  "Cache-Control": "max-age=31536000",
120
135
  },
121
136
  })];
122
- case 8:
123
- if (!(url.endsWith(".js") || url.endsWith(".css"))) return [3 /*break*/, 10];
137
+ case 12:
138
+ if (!(url.endsWith(".js") || url.endsWith(".css"))) return [3 /*break*/, 14];
124
139
  return [4 /*yield*/, fs.readFile(url, "utf-8")];
125
- case 9:
140
+ case 13:
126
141
  file = _b.sent();
127
142
  return [2 /*return*/, new Response(file, {
128
143
  headers: {
@@ -130,12 +145,38 @@ export default (function (req, context) { return __awaiter(void 0, void 0, void
130
145
  "Cache-Control": "max-age=31536000",
131
146
  },
132
147
  })];
133
- case 10:
148
+ case 14:
149
+ if (!(url.endsWith(".ttf") || url.endsWith(".woff") || url.endsWith(".woff2") || url.endsWith(".eot") || url.endsWith(".otf"))) return [3 /*break*/, 16];
150
+ return [4 /*yield*/, fs.readFile(url.split("?")[0], "utf-8")];
151
+ case 15:
152
+ file = _b.sent();
153
+ return [2 /*return*/, new Response(file, {
154
+ headers: {
155
+ "Content-Type": "font/".concat(url.split(".").pop()),
156
+ "Cache-Control": "max-age=31536000",
157
+ },
158
+ })];
159
+ case 16:
160
+ if (!url.includes('/.netlify/images')) return [3 /*break*/, 19];
161
+ return [4 /*yield*/, fetch(url)];
162
+ case 17:
163
+ res = _b.sent();
164
+ return [4 /*yield*/, res.arrayBuffer()];
165
+ case 18:
166
+ buffer = _b.sent();
167
+ mimeType = res.headers.get("Content-Type") || "application/octet-stream";
168
+ return [2 /*return*/, new Response(buffer, {
169
+ headers: {
170
+ "Content-Type": mimeType,
171
+ "Cache-Control": "max-age=31536000",
172
+ },
173
+ })];
174
+ case 19:
134
175
  templateHtml = "";
135
176
  serverFilePath = join(appPath, "dist/server/entry-server.js");
136
177
  bootstrapDirPath = join(appPath, "dist/client/assets");
137
178
  return [4 /*yield*/, import(serverFilePath)];
138
- case 11:
179
+ case 20:
139
180
  entry = _b.sent();
140
181
  bootstrap = "/assets/" +
141
182
  fsSync
@@ -149,7 +190,7 @@ export default (function (req, context) { return __awaiter(void 0, void 0, void
149
190
  handler = createStaticHandler(staticRoutes);
150
191
  fetchRequest = createFetchRequest(req, host);
151
192
  return [4 /*yield*/, handler.query(fetchRequest)];
152
- case 12:
193
+ case 21:
153
194
  context_1 = _b.sent();
154
195
  status_1 = context_1.status;
155
196
  if (status_1 === 302) {
@@ -161,7 +202,7 @@ export default (function (req, context) { return __awaiter(void 0, void 0, void
161
202
  helmetContext = {};
162
203
  router = createStaticRouter(handler.dataRoutes, context_1);
163
204
  return [4 /*yield*/, render(router, context_1, helmetContext)];
164
- case 13:
205
+ case 22:
165
206
  rendered = _b.sent();
166
207
  // Load template html
167
208
  if (!templateHtml) {
@@ -176,13 +217,13 @@ export default (function (req, context) { return __awaiter(void 0, void 0, void
176
217
  "Cache-Control": "max-age=31536000",
177
218
  },
178
219
  })];
179
- case 14:
220
+ case 23:
180
221
  e_1 = _b.sent();
181
222
  console.log(e_1.stack);
182
223
  return [2 /*return*/, new Response(e_1.stack, {
183
224
  status: 500,
184
225
  })];
185
- case 15: return [2 /*return*/];
226
+ case 24: return [2 /*return*/];
186
227
  }
187
228
  });
188
229
  }); });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rasengan",
3
3
  "private": false,
4
- "version": "1.0.0-beta.33",
4
+ "version": "1.0.0-beta.35",
5
5
  "description": "The modern frontend framework for React",
6
6
  "type": "module",
7
7
  "main": "lib/esm/index.js",