rasengan 1.0.0-beta.39 → 1.0.0-beta.40
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/lib/esm/cli/index.js
CHANGED
|
@@ -108,7 +108,7 @@ program
|
|
|
108
108
|
configPath = resolvePath(path.join(process.cwd(), "rasengan.config.js"));
|
|
109
109
|
return [4 /*yield*/, import(configPath)];
|
|
110
110
|
case 1:
|
|
111
|
-
appConfig = _c.sent();
|
|
111
|
+
appConfig = (_c.sent()).default;
|
|
112
112
|
server = appConfig.server;
|
|
113
113
|
hostingStrategy = (_b = (_a = server === null || server === void 0 ? void 0 : server.production) === null || _a === void 0 ? void 0 : _a.hosting) !== null && _b !== void 0 ? _b : "custom";
|
|
114
114
|
execa("node", ["node_modules/rasengan/lib/esm/scripts/prepare-prod"], {
|
|
@@ -53,31 +53,36 @@ import { fileTypeFromBuffer } from "file-type";
|
|
|
53
53
|
// Create server for production only
|
|
54
54
|
export default function handler(req, res) {
|
|
55
55
|
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var url, host, appPath, filePath, file, err_1, segments, segmentsWithoutOrigin, _i, segments_1, segment, filePath, file, otherFile, result, mimeType, file, templateHtml, serverFilePath, bootstrapDirPath, entry, bootstrap, styles, render, staticRoutes, loadTemplateHtml, handler_1, fetchRequest, context, status_1, redirect, helmetContext, router, rendered, html, e_1;
|
|
56
|
+
var url, host, appPath, configPath, config, filePath, file, err_1, segments, segmentsWithoutOrigin, _i, segments_1, segment, filePath, file, otherFile, result, mimeType, file, templateHtml, serverFilePath, bootstrapDirPath, entry, bootstrap, styles, render, staticRoutes, loadTemplateHtml, handler_1, fetchRequest, context, status_1, redirect, helmetContext, router, rendered, html, e_1;
|
|
57
57
|
var _a;
|
|
58
58
|
return __generator(this, function (_b) {
|
|
59
59
|
switch (_b.label) {
|
|
60
60
|
case 0:
|
|
61
|
-
_b.trys.push([0,
|
|
61
|
+
_b.trys.push([0, 18, , 19]);
|
|
62
62
|
url = req.url;
|
|
63
63
|
host = req.headers.host;
|
|
64
64
|
appPath = process.cwd();
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
console.log({ env: process.cwd() });
|
|
66
|
+
configPath = path.resolve(join(process.cwd() + "./../../", "rasengan.config.js"));
|
|
67
|
+
return [4 /*yield*/, import(configPath)];
|
|
67
68
|
case 1:
|
|
68
|
-
_b.
|
|
69
|
+
config = (_b.sent()).default;
|
|
70
|
+
if (!(url === "/robots.txt")) return [3 /*break*/, 6];
|
|
71
|
+
_b.label = 2;
|
|
72
|
+
case 2:
|
|
73
|
+
_b.trys.push([2, 5, , 6]);
|
|
69
74
|
filePath = join(appPath, "dist/client/robots.txt");
|
|
70
75
|
return [4 /*yield*/, fs.access(path.resolve(filePath))];
|
|
71
|
-
case
|
|
76
|
+
case 3:
|
|
72
77
|
_b.sent();
|
|
73
78
|
return [4 /*yield*/, fs.readFile(filePath, "utf-8")];
|
|
74
|
-
case
|
|
79
|
+
case 4:
|
|
75
80
|
file = _b.sent();
|
|
76
81
|
return [2 /*return*/, res.send(file)];
|
|
77
|
-
case
|
|
82
|
+
case 5:
|
|
78
83
|
err_1 = _b.sent();
|
|
79
84
|
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
|
-
case
|
|
85
|
+
case 6:
|
|
81
86
|
// ! Sitemap Fix
|
|
82
87
|
if (url === "/sitemap.xml") {
|
|
83
88
|
return [2 /*return*/, res.send(path.resolve(join(appPath, "dist/client/sitemap.xml")))];
|
|
@@ -86,7 +91,7 @@ export default function handler(req, res) {
|
|
|
86
91
|
if (url === "/manifest.json") {
|
|
87
92
|
return [2 /*return*/, res.send(path.resolve(join(appPath, "dist/client/manifest.json")))];
|
|
88
93
|
}
|
|
89
|
-
if (!url.includes("/assets")) return [3 /*break*/,
|
|
94
|
+
if (!url.includes("/assets")) return [3 /*break*/, 10];
|
|
90
95
|
segments = url.split("/");
|
|
91
96
|
segmentsWithoutOrigin = __spreadArray([], segments, true);
|
|
92
97
|
for (_i = 0, segments_1 = segments; _i < segments_1.length; _i++) {
|
|
@@ -98,45 +103,51 @@ export default function handler(req, res) {
|
|
|
98
103
|
}
|
|
99
104
|
filePath = join(appPath, "dist/client", segmentsWithoutOrigin.join("/"));
|
|
100
105
|
return [4 /*yield*/, fs.readFile(filePath, "utf-8")];
|
|
101
|
-
case
|
|
106
|
+
case 7:
|
|
102
107
|
file = _b.sent();
|
|
103
108
|
if (url.endsWith(".js") || url.endsWith(".css")) {
|
|
104
109
|
return [2 /*return*/, new Response(file, {
|
|
105
110
|
headers: {
|
|
106
|
-
"Content-Type": url.endsWith(".js")
|
|
111
|
+
"Content-Type": url.endsWith(".js")
|
|
112
|
+
? "text/javascript"
|
|
113
|
+
: "text/css",
|
|
107
114
|
"Cache-Control": "max-age=31536000",
|
|
108
115
|
},
|
|
109
116
|
})];
|
|
110
117
|
}
|
|
111
118
|
return [4 /*yield*/, fs.readFile(filePath)];
|
|
112
|
-
case
|
|
119
|
+
case 8:
|
|
113
120
|
otherFile = _b.sent();
|
|
114
121
|
return [4 /*yield*/, fileTypeFromBuffer(otherFile)];
|
|
115
|
-
case
|
|
122
|
+
case 9:
|
|
116
123
|
result = _b.sent();
|
|
117
|
-
mimeType = result
|
|
124
|
+
mimeType = result
|
|
125
|
+
? result.mime
|
|
126
|
+
: url.endsWith(".svg")
|
|
127
|
+
? "image/svg+xml"
|
|
128
|
+
: "application/octet-stream";
|
|
118
129
|
return [2 /*return*/, new Response(otherFile, {
|
|
119
130
|
headers: {
|
|
120
131
|
"Content-Type": mimeType,
|
|
121
132
|
"Cache-Control": "max-age=31536000",
|
|
122
133
|
},
|
|
123
134
|
})];
|
|
124
|
-
case 9:
|
|
125
|
-
if (!(url.endsWith(".js") || url.endsWith(".css"))) return [3 /*break*/, 11];
|
|
126
|
-
return [4 /*yield*/, fs.readFile(url, "utf-8")];
|
|
127
135
|
case 10:
|
|
136
|
+
if (!(url.endsWith(".js") || url.endsWith(".css"))) return [3 /*break*/, 12];
|
|
137
|
+
return [4 /*yield*/, fs.readFile(url, "utf-8")];
|
|
138
|
+
case 11:
|
|
128
139
|
file = _b.sent();
|
|
129
140
|
return [2 /*return*/, res
|
|
130
141
|
.status(200)
|
|
131
142
|
.setHeader("Content-Type", url.endsWith(".js") ? "text/javascript" : "text/css")
|
|
132
143
|
.setHeader("Cache-Control", "max-age=31536000")
|
|
133
144
|
.end(file)];
|
|
134
|
-
case
|
|
145
|
+
case 12:
|
|
135
146
|
templateHtml = "";
|
|
136
147
|
serverFilePath = join(appPath, "dist/server/entry-server.js");
|
|
137
148
|
bootstrapDirPath = join(appPath, "dist/client/assets");
|
|
138
149
|
return [4 /*yield*/, import(serverFilePath)];
|
|
139
|
-
case
|
|
150
|
+
case 13:
|
|
140
151
|
entry = _b.sent();
|
|
141
152
|
bootstrap = "/assets/" +
|
|
142
153
|
fsSync
|
|
@@ -150,7 +161,7 @@ export default function handler(req, res) {
|
|
|
150
161
|
handler_1 = createStaticHandler(staticRoutes);
|
|
151
162
|
fetchRequest = createFetchRequest(req, host);
|
|
152
163
|
return [4 /*yield*/, handler_1.query(fetchRequest)];
|
|
153
|
-
case
|
|
164
|
+
case 14:
|
|
154
165
|
context = _b.sent();
|
|
155
166
|
status_1 = context.status;
|
|
156
167
|
if (status_1 === 302) {
|
|
@@ -160,8 +171,11 @@ export default function handler(req, res) {
|
|
|
160
171
|
}
|
|
161
172
|
helmetContext = {};
|
|
162
173
|
router = createStaticRouter(handler_1.dataRoutes, context);
|
|
163
|
-
return [
|
|
164
|
-
|
|
174
|
+
if (!config.experimental.stream) return [3 /*break*/, 16];
|
|
175
|
+
return [4 /*yield*/, render(router, context, helmetContext, bootstrap, styles, res)];
|
|
176
|
+
case 15: return [2 /*return*/, _b.sent()];
|
|
177
|
+
case 16: return [4 /*yield*/, render(router, context, helmetContext)];
|
|
178
|
+
case 17:
|
|
165
179
|
rendered = _b.sent();
|
|
166
180
|
// Load template html
|
|
167
181
|
if (!templateHtml) {
|
|
@@ -174,12 +188,12 @@ export default function handler(req, res) {
|
|
|
174
188
|
.setHeader("Content-Type", "text/html")
|
|
175
189
|
.setHeader("Cache-Control", "max-age=31536000")
|
|
176
190
|
.end(html)];
|
|
177
|
-
case
|
|
191
|
+
case 18:
|
|
178
192
|
e_1 = _b.sent();
|
|
179
193
|
console.log(e_1.stack);
|
|
180
194
|
res.status(500).end(e_1.stack);
|
|
181
|
-
return [3 /*break*/,
|
|
182
|
-
case
|
|
195
|
+
return [3 /*break*/, 19];
|
|
196
|
+
case 19: return [2 /*return*/];
|
|
183
197
|
}
|
|
184
198
|
});
|
|
185
199
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { VercelRequest, VercelResponse } from "@vercel/node";
|
|
2
|
-
export default function handler(req: VercelRequest, res: VercelResponse): Promise<
|
|
2
|
+
export default function handler(req: VercelRequest, res: VercelResponse): Promise<any>;
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -227,6 +227,7 @@ async function createServer({
|
|
|
227
227
|
base,
|
|
228
228
|
enableSearchingPort: true,
|
|
229
229
|
open,
|
|
230
|
+
config,
|
|
230
231
|
});
|
|
231
232
|
} else {
|
|
232
233
|
console.log(chalk.blue(`Trying port ${newPort}... \n\n`));
|
|
@@ -237,6 +238,7 @@ async function createServer({
|
|
|
237
238
|
base,
|
|
238
239
|
enableSearchingPort,
|
|
239
240
|
open,
|
|
241
|
+
config,
|
|
240
242
|
});
|
|
241
243
|
}
|
|
242
244
|
}
|