rasengan 1.0.0-beta.8 → 1.0.0-beta.9
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.
|
@@ -63,62 +63,62 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
63
63
|
};
|
|
64
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
65
|
var promises_1 = __importDefault(require("node:fs/promises"));
|
|
66
|
-
var
|
|
67
|
-
var
|
|
66
|
+
var node_fs_1 = __importDefault(require("node:fs"));
|
|
67
|
+
var node_path_1 = __importStar(require("node:path"));
|
|
68
|
+
var node_url_1 = require("node:url");
|
|
68
69
|
var server_js_1 = require("react-router-dom/server.js");
|
|
69
70
|
// @ts-ignore
|
|
70
71
|
var rasengan_1 = require("rasengan");
|
|
71
72
|
// @ts-ignore
|
|
72
|
-
var __filename = (0,
|
|
73
|
-
var __dirname = (0,
|
|
73
|
+
var __filename = (0, node_url_1.fileURLToPath)(import.meta.url);
|
|
74
|
+
var __dirname = (0, node_path_1.dirname)(__filename);
|
|
74
75
|
// Create server for production only
|
|
75
76
|
function handler(req, res) {
|
|
76
77
|
var _a;
|
|
77
78
|
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
var url, host, appPath,
|
|
79
|
+
var url, host, appPath, err_1, templateHtml, serverFilePath, bootstrapDirPath, entry, bootstrap, render, staticRoutes, loadTemplateHtml, handler_1, fetchRequest, context, status_1, redirect, helmetContext, router, rendered, html, e_1;
|
|
79
80
|
return __generator(this, function (_b) {
|
|
80
81
|
switch (_b.label) {
|
|
81
82
|
case 0:
|
|
82
|
-
_b.trys.push([0,
|
|
83
|
+
_b.trys.push([0, 8, , 9]);
|
|
83
84
|
url = req.url;
|
|
84
85
|
host = req.headers.host;
|
|
85
|
-
appPath = (0,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
appPath = (0, node_path_1.join)(__dirname, "..");
|
|
87
|
+
if (!(url === "/robots.txt")) return [3 /*break*/, 4];
|
|
88
|
+
_b.label = 1;
|
|
89
|
+
case 1:
|
|
90
|
+
_b.trys.push([1, 3, , 4]);
|
|
91
|
+
return [4 /*yield*/, promises_1.default.access(node_path_1.default.resolve((0, node_path_1.join)(appPath, "dist/client/robots.txt")))];
|
|
92
|
+
case 2:
|
|
93
|
+
_b.sent();
|
|
94
|
+
return [2 /*return*/, res.send(node_path_1.default.resolve((0, node_path_1.join)(appPath, "dist/client/robots.txt")))];
|
|
95
|
+
case 3:
|
|
96
|
+
err_1 = _b.sent();
|
|
97
|
+
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 ")];
|
|
98
|
+
case 4:
|
|
94
99
|
// ! Sitemap Fix
|
|
95
100
|
if (url === "/sitemap.xml") {
|
|
96
|
-
return [2 /*return*/, res.send(
|
|
101
|
+
return [2 /*return*/, res.send(node_path_1.default.resolve((0, node_path_1.join)(appPath, "dist/client/sitemap.xml")))];
|
|
97
102
|
}
|
|
98
103
|
// ! Manifest Fix
|
|
99
104
|
if (url === "/manifest.json") {
|
|
100
|
-
return [2 /*return*/, res.send(
|
|
105
|
+
return [2 /*return*/, res.send(node_path_1.default.resolve((0, node_path_1.join)(appPath, "dist/client/manifest.json")))];
|
|
101
106
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
serverFilePath = (0, path_1.join)(appPath, "dist/server/entry-server.js");
|
|
106
|
-
return [4 /*yield*/, promises_1.default.readFile(htmlFilePath, "utf-8")];
|
|
107
|
-
case 1:
|
|
108
|
-
// const ssrManifestFilePath = join(
|
|
109
|
-
// appPath,
|
|
110
|
-
// "dist/client/.vite/ssr-manifest.json"
|
|
111
|
-
// );
|
|
112
|
-
// Read template, server-renderer and manifest in production
|
|
113
|
-
template = _b.sent();
|
|
107
|
+
templateHtml = "";
|
|
108
|
+
serverFilePath = (0, node_path_1.join)(appPath, "dist/server/entry-server.js");
|
|
109
|
+
bootstrapDirPath = (0, node_path_1.join)(appPath, "dist/client/assets");
|
|
114
110
|
return [4 /*yield*/, Promise.resolve("".concat(serverFilePath)).then(function (s) { return __importStar(require(s)); })];
|
|
115
|
-
case
|
|
111
|
+
case 5:
|
|
116
112
|
entry = _b.sent();
|
|
117
|
-
|
|
113
|
+
bootstrap = "/assets/" +
|
|
114
|
+
node_fs_1.default
|
|
115
|
+
.readdirSync(bootstrapDirPath)
|
|
116
|
+
.filter(function (fn) { return fn.includes("entry-client") && fn.endsWith(".js"); })[0];
|
|
117
|
+
render = entry.render, staticRoutes = entry.staticRoutes, loadTemplateHtml = entry.loadTemplateHtml;
|
|
118
118
|
handler_1 = (0, server_js_1.createStaticHandler)(staticRoutes);
|
|
119
119
|
fetchRequest = (0, rasengan_1.createFetchRequest)(req, host);
|
|
120
120
|
return [4 /*yield*/, handler_1.query(fetchRequest)];
|
|
121
|
-
case
|
|
121
|
+
case 6:
|
|
122
122
|
context = _b.sent();
|
|
123
123
|
status_1 = context.status;
|
|
124
124
|
if (status_1 === 302) {
|
|
@@ -129,25 +129,26 @@ function handler(req, res) {
|
|
|
129
129
|
helmetContext = {};
|
|
130
130
|
router = (0, server_js_1.createStaticRouter)(handler_1.dataRoutes, context);
|
|
131
131
|
return [4 /*yield*/, render(router, context, helmetContext)];
|
|
132
|
-
case
|
|
132
|
+
case 7:
|
|
133
133
|
rendered = _b.sent();
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
// Load template html
|
|
135
|
+
if (!templateHtml) {
|
|
136
|
+
templateHtml = loadTemplateHtml(helmetContext, bootstrap);
|
|
137
|
+
}
|
|
138
|
+
html = templateHtml.replace("rasengan-body-app", (_a = rendered.html) !== null && _a !== void 0 ? _a : "");
|
|
139
|
+
// Send the rendered html page
|
|
139
140
|
res
|
|
140
141
|
.status(200)
|
|
141
142
|
.setHeader("Content-Type", "text/html")
|
|
142
143
|
.setHeader("Cache-Control", "max-age=31536000")
|
|
143
144
|
.end(html);
|
|
144
|
-
return [3 /*break*/,
|
|
145
|
-
case
|
|
145
|
+
return [3 /*break*/, 9];
|
|
146
|
+
case 8:
|
|
146
147
|
e_1 = _b.sent();
|
|
147
148
|
console.log(e_1.stack);
|
|
148
149
|
res.status(500).end(e_1.stack);
|
|
149
|
-
return [3 /*break*/,
|
|
150
|
-
case
|
|
150
|
+
return [3 /*break*/, 9];
|
|
151
|
+
case 9: return [2 /*return*/];
|
|
151
152
|
}
|
|
152
153
|
});
|
|
153
154
|
});
|
|
@@ -35,8 +35,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
import fs from "node:fs/promises";
|
|
38
|
-
import
|
|
39
|
-
import {
|
|
38
|
+
import fsSync from "node:fs";
|
|
39
|
+
import path, { join, dirname } from "node:path";
|
|
40
|
+
import { fileURLToPath } from "node:url";
|
|
40
41
|
import { createStaticHandler, createStaticRouter, } from "react-router-dom/server.js";
|
|
41
42
|
// @ts-ignore
|
|
42
43
|
import { createFetchRequest } from "rasengan";
|
|
@@ -47,22 +48,26 @@ var __dirname = dirname(__filename);
|
|
|
47
48
|
export default function handler(req, res) {
|
|
48
49
|
var _a;
|
|
49
50
|
return __awaiter(this, void 0, void 0, function () {
|
|
50
|
-
var url, host, appPath,
|
|
51
|
+
var url, host, appPath, err_1, templateHtml, serverFilePath, bootstrapDirPath, entry, bootstrap, render, staticRoutes, loadTemplateHtml, handler_1, fetchRequest, context, status_1, redirect, helmetContext, router, rendered, html, e_1;
|
|
51
52
|
return __generator(this, function (_b) {
|
|
52
53
|
switch (_b.label) {
|
|
53
54
|
case 0:
|
|
54
|
-
_b.trys.push([0,
|
|
55
|
+
_b.trys.push([0, 8, , 9]);
|
|
55
56
|
url = req.url;
|
|
56
57
|
host = req.headers.host;
|
|
57
58
|
appPath = join(__dirname, "..");
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
if (!(url === "/robots.txt")) return [3 /*break*/, 4];
|
|
60
|
+
_b.label = 1;
|
|
61
|
+
case 1:
|
|
62
|
+
_b.trys.push([1, 3, , 4]);
|
|
63
|
+
return [4 /*yield*/, fs.access(path.resolve(join(appPath, "dist/client/robots.txt")))];
|
|
64
|
+
case 2:
|
|
65
|
+
_b.sent();
|
|
66
|
+
return [2 /*return*/, res.send(path.resolve(join(appPath, "dist/client/robots.txt")))];
|
|
67
|
+
case 3:
|
|
68
|
+
err_1 = _b.sent();
|
|
69
|
+
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 ")];
|
|
70
|
+
case 4:
|
|
66
71
|
// ! Sitemap Fix
|
|
67
72
|
if (url === "/sitemap.xml") {
|
|
68
73
|
return [2 /*return*/, res.send(path.resolve(join(appPath, "dist/client/sitemap.xml")))];
|
|
@@ -71,26 +76,21 @@ export default function handler(req, res) {
|
|
|
71
76
|
if (url === "/manifest.json") {
|
|
72
77
|
return [2 /*return*/, res.send(path.resolve(join(appPath, "dist/client/manifest.json")))];
|
|
73
78
|
}
|
|
74
|
-
|
|
75
|
-
entry = void 0;
|
|
76
|
-
htmlFilePath = join(appPath, "dist/client/index.html");
|
|
79
|
+
templateHtml = "";
|
|
77
80
|
serverFilePath = join(appPath, "dist/server/entry-server.js");
|
|
78
|
-
|
|
79
|
-
case 1:
|
|
80
|
-
// const ssrManifestFilePath = join(
|
|
81
|
-
// appPath,
|
|
82
|
-
// "dist/client/.vite/ssr-manifest.json"
|
|
83
|
-
// );
|
|
84
|
-
// Read template, server-renderer and manifest in production
|
|
85
|
-
template = _b.sent();
|
|
81
|
+
bootstrapDirPath = join(appPath, "dist/client/assets");
|
|
86
82
|
return [4 /*yield*/, import(serverFilePath)];
|
|
87
|
-
case
|
|
83
|
+
case 5:
|
|
88
84
|
entry = _b.sent();
|
|
89
|
-
|
|
85
|
+
bootstrap = "/assets/" +
|
|
86
|
+
fsSync
|
|
87
|
+
.readdirSync(bootstrapDirPath)
|
|
88
|
+
.filter(function (fn) { return fn.includes("entry-client") && fn.endsWith(".js"); })[0];
|
|
89
|
+
render = entry.render, staticRoutes = entry.staticRoutes, loadTemplateHtml = entry.loadTemplateHtml;
|
|
90
90
|
handler_1 = createStaticHandler(staticRoutes);
|
|
91
91
|
fetchRequest = createFetchRequest(req, host);
|
|
92
92
|
return [4 /*yield*/, handler_1.query(fetchRequest)];
|
|
93
|
-
case
|
|
93
|
+
case 6:
|
|
94
94
|
context = _b.sent();
|
|
95
95
|
status_1 = context.status;
|
|
96
96
|
if (status_1 === 302) {
|
|
@@ -101,25 +101,26 @@ export default function handler(req, res) {
|
|
|
101
101
|
helmetContext = {};
|
|
102
102
|
router = createStaticRouter(handler_1.dataRoutes, context);
|
|
103
103
|
return [4 /*yield*/, render(router, context, helmetContext)];
|
|
104
|
-
case
|
|
104
|
+
case 7:
|
|
105
105
|
rendered = _b.sent();
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
// Load template html
|
|
107
|
+
if (!templateHtml) {
|
|
108
|
+
templateHtml = loadTemplateHtml(helmetContext, bootstrap);
|
|
109
|
+
}
|
|
110
|
+
html = templateHtml.replace("rasengan-body-app", (_a = rendered.html) !== null && _a !== void 0 ? _a : "");
|
|
111
|
+
// Send the rendered html page
|
|
111
112
|
res
|
|
112
113
|
.status(200)
|
|
113
114
|
.setHeader("Content-Type", "text/html")
|
|
114
115
|
.setHeader("Cache-Control", "max-age=31536000")
|
|
115
116
|
.end(html);
|
|
116
|
-
return [3 /*break*/,
|
|
117
|
-
case
|
|
117
|
+
return [3 /*break*/, 9];
|
|
118
|
+
case 8:
|
|
118
119
|
e_1 = _b.sent();
|
|
119
120
|
console.log(e_1.stack);
|
|
120
121
|
res.status(500).end(e_1.stack);
|
|
121
|
-
return [3 /*break*/,
|
|
122
|
-
case
|
|
122
|
+
return [3 /*break*/, 9];
|
|
123
|
+
case 9: return [2 /*return*/];
|
|
123
124
|
}
|
|
124
125
|
});
|
|
125
126
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { RouterComponent } from "../routing/interfaces.js";
|
|
3
3
|
import { Metadata } from "../routing/index.js";
|
|
4
|
+
import { MetadataWithoutTitleAndDescription } from "../routing/types.js";
|
|
4
5
|
/**
|
|
5
6
|
* Props for App component
|
|
6
7
|
*/
|
|
@@ -54,7 +55,7 @@ export type LayoutComponent = React.FC<ReactComponentProps> & {
|
|
|
54
55
|
/**
|
|
55
56
|
* Metadata for the page
|
|
56
57
|
*/
|
|
57
|
-
metadata?:
|
|
58
|
+
metadata?: MetadataWithoutTitleAndDescription;
|
|
58
59
|
/**
|
|
59
60
|
* Loader function that loads data for the page from the server
|
|
60
61
|
*/
|
|
@@ -67,16 +68,7 @@ export type PageComponent = LayoutComponent & {
|
|
|
67
68
|
/**
|
|
68
69
|
* Metadata for the page omit title
|
|
69
70
|
*/
|
|
70
|
-
metadata?: Metadata
|
|
71
|
-
/**
|
|
72
|
-
* Title of the pate
|
|
73
|
-
*/
|
|
74
|
-
title?: string;
|
|
75
|
-
/**
|
|
76
|
-
* Description of the page
|
|
77
|
-
*/
|
|
78
|
-
description?: string;
|
|
79
|
-
};
|
|
71
|
+
metadata?: Metadata;
|
|
80
72
|
};
|
|
81
73
|
/**
|
|
82
74
|
* Helmet context type
|
|
@@ -13,7 +13,7 @@ export type MetaTag = {
|
|
|
13
13
|
property?: string;
|
|
14
14
|
content: string;
|
|
15
15
|
};
|
|
16
|
-
export type
|
|
16
|
+
export type MetadataWithoutTitleAndDescription = {
|
|
17
17
|
/**
|
|
18
18
|
* Configuring link preview on social media like facebook, linkedin, etc.
|
|
19
19
|
*/
|
|
@@ -46,3 +46,13 @@ export type Metadata = {
|
|
|
46
46
|
*/
|
|
47
47
|
metaTags?: Array<MetaTag>;
|
|
48
48
|
};
|
|
49
|
+
export type Metadata = MetadataWithoutTitleAndDescription & {
|
|
50
|
+
/**
|
|
51
|
+
* Title of the pate
|
|
52
|
+
*/
|
|
53
|
+
title?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Description of the page
|
|
56
|
+
*/
|
|
57
|
+
description?: string;
|
|
58
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rasengan",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.9",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/esm/index.js",
|
|
7
7
|
"bin": {
|
|
@@ -40,18 +40,19 @@
|
|
|
40
40
|
"homepage": "https://rasengan.dev",
|
|
41
41
|
"scripts": {
|
|
42
42
|
"dev": "node server",
|
|
43
|
+
"preview": "cross-env NODE_ENV=production node server",
|
|
44
|
+
|
|
43
45
|
"build": "npm run build:client && npm run build:server",
|
|
44
46
|
"build:client": "vite build --ssrManifest --outDir dist/client",
|
|
45
|
-
"build:server": "vite build --ssr node_modules/rasengan/lib/entries/entry-server.js --outDir dist/server",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
47
|
+
"build:server": "vite build --ssr node_modules/rasengan/lib/esm/entries/entry-server.js --outDir dist/server",
|
|
48
|
+
"compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json",
|
|
49
|
+
"build:lib:clean": "rm -rf ./lib",
|
|
50
|
+
"build:lib:all": "npm-run-all build:lib:clean compile",
|
|
51
|
+
|
|
48
52
|
"deploy": "npm publish --access public",
|
|
49
53
|
"deploy:beta": "npm run deploy --tag beta",
|
|
50
|
-
"pack": "npm pack --pack-destination ./../packages/rasengan/"
|
|
54
|
+
"pack": "npm pack --pack-destination ./../packages/rasengan/"
|
|
51
55
|
|
|
52
|
-
"compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json",
|
|
53
|
-
"build:lib:clean": "rm -rf ./lib",
|
|
54
|
-
"build:lib:all": "npm-run-all build:lib:clean compile"
|
|
55
56
|
},
|
|
56
57
|
"dependencies": {
|
|
57
58
|
"@vercel/node": "^3.0.14",
|
package/server.js
CHANGED
|
@@ -77,15 +77,10 @@ async function createServer({
|
|
|
77
77
|
let entry;
|
|
78
78
|
|
|
79
79
|
if (!isProduction) {
|
|
80
|
-
let folder = "esm";
|
|
81
|
-
|
|
82
|
-
// if (typeof require === undefined || typeof __dirname === undefined)
|
|
83
|
-
// folder = "esm";
|
|
84
|
-
|
|
85
80
|
entry = await vite.ssrLoadModule(
|
|
86
81
|
join(
|
|
87
82
|
appPath,
|
|
88
|
-
`node_modules/rasengan/lib
|
|
83
|
+
`node_modules/rasengan/lib/esm/entries/entry-server.js`
|
|
89
84
|
)
|
|
90
85
|
);
|
|
91
86
|
} else {
|