rasengan 1.0.0-beta.1
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/LICENSE +21 -0
- package/lib/cli/dirname.d.ts +2 -0
- package/lib/cli/dirname.js +6 -0
- package/lib/cli/dirname.js.map +1 -0
- package/lib/cli/index.d.ts +2 -0
- package/lib/cli/index.js +101 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/config/index.d.ts +39 -0
- package/lib/config/index.js +57 -0
- package/lib/config/index.js.map +1 -0
- package/lib/config/type.d.ts +68 -0
- package/lib/config/type.js +2 -0
- package/lib/config/type.js.map +1 -0
- package/lib/core/components/index.d.ts +26 -0
- package/lib/core/components/index.js +72 -0
- package/lib/core/components/index.js.map +1 -0
- package/lib/core/index.d.ts +2 -0
- package/lib/core/index.js +2 -0
- package/lib/core/index.js.map +1 -0
- package/lib/core/interfaces.d.ts +76 -0
- package/lib/core/interfaces.js +91 -0
- package/lib/core/interfaces.js.map +1 -0
- package/lib/core/types.d.ts +45 -0
- package/lib/core/types.js +2 -0
- package/lib/core/types.js.map +1 -0
- package/lib/decorators/index.d.ts +2 -0
- package/lib/decorators/index.js +3 -0
- package/lib/decorators/index.js.map +1 -0
- package/lib/decorators/route.d.ts +7 -0
- package/lib/decorators/route.js +25 -0
- package/lib/decorators/route.js.map +1 -0
- package/lib/decorators/router.d.ts +7 -0
- package/lib/decorators/router.js +24 -0
- package/lib/decorators/router.js.map +1 -0
- package/lib/decorators/types.d.ts +47 -0
- package/lib/decorators/types.js +2 -0
- package/lib/decorators/types.js.map +1 -0
- package/lib/entries/entry-client.d.ts +1 -0
- package/lib/entries/entry-client.js +15 -0
- package/lib/entries/entry-client.js.map +1 -0
- package/lib/entries/entry-server.d.ts +6 -0
- package/lib/entries/entry-server.js +20 -0
- package/lib/entries/entry-server.js.map +1 -0
- package/lib/hooks/index.d.ts +0 -0
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/index.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -0
- package/lib/routing/components/index.d.ts +32 -0
- package/lib/routing/components/index.js +69 -0
- package/lib/routing/components/index.js.map +1 -0
- package/lib/routing/index.d.ts +3 -0
- package/lib/routing/index.js +4 -0
- package/lib/routing/index.js.map +1 -0
- package/lib/routing/interfaces.d.ts +67 -0
- package/lib/routing/interfaces.js +88 -0
- package/lib/routing/interfaces.js.map +1 -0
- package/lib/routing/types.d.ts +4 -0
- package/lib/routing/types.js +2 -0
- package/lib/routing/types.js.map +1 -0
- package/lib/routing/utils/index.d.ts +40 -0
- package/lib/routing/utils/index.js +256 -0
- package/lib/routing/utils/index.js.map +1 -0
- package/lib/server/functions/vercel/api/index.d.ts +2 -0
- package/lib/server/functions/vercel/api/index.js +91 -0
- package/lib/server/functions/vercel/api/index.js.map +1 -0
- package/lib/server/functions/vercel/vercel.json +12 -0
- package/lib/server/utils/createFetchRequest.d.ts +5 -0
- package/lib/server/utils/createFetchRequest.js +34 -0
- package/lib/server/utils/createFetchRequest.js.map +1 -0
- package/lib/server/utils/getIp.d.ts +1 -0
- package/lib/server/utils/getIp.js +30 -0
- package/lib/server/utils/getIp.js.map +1 -0
- package/lib/server/utils/handleError.d.ts +2 -0
- package/lib/server/utils/handleError.js +28 -0
- package/lib/server/utils/handleError.js.map +1 -0
- package/lib/server/utils/index.d.ts +5 -0
- package/lib/server/utils/index.js +8 -0
- package/lib/server/utils/index.js.map +1 -0
- package/lib/server/utils/log.d.ts +6 -0
- package/lib/server/utils/log.js +69 -0
- package/lib/server/utils/log.js.map +1 -0
- package/package.json +75 -0
- package/server.js +229 -0
- package/src/cli/dirname.ts +7 -0
- package/src/cli/index.ts +134 -0
- package/src/config/index.ts +67 -0
- package/src/config/type.ts +76 -0
- package/src/core/components/index.tsx +111 -0
- package/src/core/index.ts +14 -0
- package/src/core/interfaces.tsx +129 -0
- package/src/core/types.ts +43 -0
- package/src/decorators/index.ts +2 -0
- package/src/decorators/route.ts +32 -0
- package/src/decorators/router.ts +30 -0
- package/src/decorators/types.ts +54 -0
- package/src/entries/entry-client.tsx +33 -0
- package/src/entries/entry-server.tsx +50 -0
- package/src/hooks/index.ts +0 -0
- package/src/index.ts +11 -0
- package/src/routing/components/index.tsx +125 -0
- package/src/routing/index.ts +23 -0
- package/src/routing/interfaces.ts +105 -0
- package/src/routing/types.ts +3 -0
- package/src/routing/utils/index.tsx +342 -0
- package/src/server/functions/vercel/api/index.ts +122 -0
- package/src/server/functions/vercel/vercel.json +12 -0
- package/src/server/utils/createFetchRequest.ts +40 -0
- package/src/server/utils/getIp.ts +37 -0
- package/src/server/utils/handleError.ts +36 -0
- package/src/server/utils/index.ts +15 -0
- package/src/server/utils/log.ts +115 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +30 -0
- package/tsconfig.lib.json +41 -0
- package/tsconfig.node.json +11 -0
- package/vite.config.ts +45 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { RouterProvider, createBrowserRouter } from "react-router-dom";
|
|
3
|
+
import { DefaultLayout } from "../../index.js";
|
|
4
|
+
import { ClientComponent, NotFoundComponentContainer, NotFoundPageComponent, ServerComponent, } from "../components/index.js";
|
|
5
|
+
import { RouteErrorBoundary as ErrorBoundary } from "../../core/components/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* This function receives a router component and get a formated router first
|
|
8
|
+
* and then return a router.
|
|
9
|
+
*/
|
|
10
|
+
export const getRouter = (router) => {
|
|
11
|
+
const routes = generateBrowserRoutes(router);
|
|
12
|
+
let Router = createBrowserRouter(routes);
|
|
13
|
+
return () => (_jsx(RouterProvider, { fallbackElement: _jsx(_Fragment, { children: "Not Found" }), router: Router }));
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* This function receives a router component and return a formated router.
|
|
17
|
+
*/
|
|
18
|
+
const generateBrowserRoutes = (router, isRoot = true) => {
|
|
19
|
+
// Initialization of the list of routes
|
|
20
|
+
const routes = [];
|
|
21
|
+
// Get information about the layout and the path
|
|
22
|
+
const layout = router.layout;
|
|
23
|
+
const LayoutToRender = layout.render;
|
|
24
|
+
const route = {
|
|
25
|
+
path: layout.path,
|
|
26
|
+
elementError: _jsx(ErrorBoundary, {}),
|
|
27
|
+
element: _jsx(LayoutToRender, {}),
|
|
28
|
+
children: [],
|
|
29
|
+
};
|
|
30
|
+
// Defining the page not found route
|
|
31
|
+
if (isRoot) {
|
|
32
|
+
routes.push({
|
|
33
|
+
path: "*",
|
|
34
|
+
element: (_jsx(NotFoundComponentContainer, { content: router.notFoundComponent })),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
// Get informations about pages
|
|
38
|
+
const pages = router.pages.map((page) => {
|
|
39
|
+
// Get the path of the page
|
|
40
|
+
const path = page.path === "/" ? layout.path : page.path;
|
|
41
|
+
return {
|
|
42
|
+
path,
|
|
43
|
+
loader: async ({ params, request }) => {
|
|
44
|
+
// Get the response from the loader
|
|
45
|
+
const response = await page.loader({ params, request });
|
|
46
|
+
// Handle redirection
|
|
47
|
+
if (response.redirect) {
|
|
48
|
+
const formData = new FormData();
|
|
49
|
+
formData.append("redirect", response.redirect);
|
|
50
|
+
return new Response(formData, {
|
|
51
|
+
status: 302,
|
|
52
|
+
headers: {
|
|
53
|
+
Location: response.redirect,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return response;
|
|
58
|
+
},
|
|
59
|
+
element: (_jsx(ClientComponent, { page: page, loader: router.loaderComponent({}) })),
|
|
60
|
+
elementError: _jsx(ErrorBoundary, {}),
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
// Add pages into children of the current route
|
|
64
|
+
pages.forEach((page) => {
|
|
65
|
+
route.children.push(page);
|
|
66
|
+
});
|
|
67
|
+
// Loop throug sub routers in order to apply the same thing.
|
|
68
|
+
// for (const SubRouter of router.routers) {
|
|
69
|
+
// const subRouter = new SubRouter();
|
|
70
|
+
// const subRoutes = generateBrowserRoutes(subRouter);
|
|
71
|
+
// // Add sub routes into the lists of route
|
|
72
|
+
// route.children.push(subRoutes);
|
|
73
|
+
// }
|
|
74
|
+
routes.push(route);
|
|
75
|
+
// Loop throug besides routers in order to apply the same thing.
|
|
76
|
+
for (const besideRouter of router.routers) {
|
|
77
|
+
const besidesRoutes = generateBrowserRoutes(besideRouter, false);
|
|
78
|
+
// Add besides routes into the lists of route
|
|
79
|
+
routes.push(...besidesRoutes);
|
|
80
|
+
}
|
|
81
|
+
// Return the formated router
|
|
82
|
+
return routes;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* This function receives a router component and return a formated router for static routing
|
|
86
|
+
* @param router Represents the router component
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
export const generateStaticRoutes = (router, isRoot = true) => {
|
|
90
|
+
// Initialization of the list of routes
|
|
91
|
+
const routes = [];
|
|
92
|
+
// Get information about the layout and the path
|
|
93
|
+
const layout = router.layout;
|
|
94
|
+
const LayoutToRender = layout.render;
|
|
95
|
+
const route = {
|
|
96
|
+
path: layout.path,
|
|
97
|
+
elementError: _jsx(ErrorBoundary, {}),
|
|
98
|
+
element: _jsx(LayoutToRender, {}),
|
|
99
|
+
children: [],
|
|
100
|
+
};
|
|
101
|
+
// Defining the page not found route
|
|
102
|
+
if (isRoot) {
|
|
103
|
+
routes.push({
|
|
104
|
+
path: "*",
|
|
105
|
+
element: (_jsx(NotFoundComponentContainer, { content: router.notFoundComponent })),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// Get informations about pages
|
|
109
|
+
const pages = router.pages.map((page) => {
|
|
110
|
+
// Get the path of the page
|
|
111
|
+
const path = page.path === "/" ? layout.path : page.path;
|
|
112
|
+
return {
|
|
113
|
+
path,
|
|
114
|
+
async loader({ params, request }) {
|
|
115
|
+
// Get the response from the loader
|
|
116
|
+
const response = await page.loader({ params, request });
|
|
117
|
+
// Handle redirection
|
|
118
|
+
if (response.redirect) {
|
|
119
|
+
const formData = new FormData();
|
|
120
|
+
formData.append("redirect", response.redirect);
|
|
121
|
+
return new Response(formData, {
|
|
122
|
+
status: 302,
|
|
123
|
+
headers: {
|
|
124
|
+
Location: response.redirect,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return response;
|
|
129
|
+
},
|
|
130
|
+
Component() {
|
|
131
|
+
return (_jsx(ServerComponent, { page: page, loader: router.loaderComponent({}) }));
|
|
132
|
+
},
|
|
133
|
+
elementError: _jsx(ErrorBoundary, {}),
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
// Add pages into children of the current route
|
|
137
|
+
pages.forEach((page) => {
|
|
138
|
+
route.children.push(page);
|
|
139
|
+
});
|
|
140
|
+
// Loop throug sub routers in order to apply the same thing.
|
|
141
|
+
// for (const SubRouter of router.routers) {
|
|
142
|
+
// const subRouter = new SubRouter();
|
|
143
|
+
// const subRoutes = generateStaticRoutes(subRouter);
|
|
144
|
+
// // Add sub routes into the lists of route
|
|
145
|
+
// route.children.push(subRoutes);
|
|
146
|
+
// }
|
|
147
|
+
routes.push(route);
|
|
148
|
+
// Loop throug besides routers in order to apply the same thing.
|
|
149
|
+
for (const besideRouter of router.routers) {
|
|
150
|
+
const besidesRoutes = generateStaticRoutes(besideRouter, false);
|
|
151
|
+
// Add besides routes into the lists of route
|
|
152
|
+
routes.push(...besidesRoutes);
|
|
153
|
+
}
|
|
154
|
+
// Return the formated router
|
|
155
|
+
return routes;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* This function receives a router component and extract all metadatas of all pages
|
|
159
|
+
* and put all of them inside a map function in order to be used to enhance ssr
|
|
160
|
+
*/
|
|
161
|
+
export const extractPageMetadata = (router) => {
|
|
162
|
+
// Initialisation of the Map of metadata
|
|
163
|
+
const metadatas = new Map();
|
|
164
|
+
// Get base url
|
|
165
|
+
const baseURL = router.layout.path;
|
|
166
|
+
// Get informations about pages of the main router
|
|
167
|
+
router.pages.forEach((page) => {
|
|
168
|
+
// Add the first slash if not exists from the page path
|
|
169
|
+
const pagePath = page.path[0] === "/" ? page.path : "/" + page.path;
|
|
170
|
+
// Remove the last slash if exists from the base url
|
|
171
|
+
const finalBaseURL = baseURL === "/"
|
|
172
|
+
? baseURL
|
|
173
|
+
: baseURL[baseURL.length - 1] === "/"
|
|
174
|
+
? baseURL.slice(0, -1)
|
|
175
|
+
: baseURL;
|
|
176
|
+
// Get the path of the page
|
|
177
|
+
const path = pagePath === "/"
|
|
178
|
+
? finalBaseURL
|
|
179
|
+
: finalBaseURL === "/"
|
|
180
|
+
? pagePath
|
|
181
|
+
: finalBaseURL + "/" + pagePath;
|
|
182
|
+
// Add metadata
|
|
183
|
+
metadatas.set(path, {
|
|
184
|
+
title: page.title,
|
|
185
|
+
description: page.description,
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
// Loop through the others routers recursively
|
|
189
|
+
for (let besidesRouter of router.routers) {
|
|
190
|
+
const data = extractPageMetadata(besidesRouter);
|
|
191
|
+
// Copy metadata from data to metadatas map
|
|
192
|
+
data.forEach((value, key) => {
|
|
193
|
+
metadatas.set(key, value);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return metadatas;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* This function adds metadata to a page or a layout
|
|
200
|
+
* @param option
|
|
201
|
+
* @returns
|
|
202
|
+
*/
|
|
203
|
+
export const defineRoutePage = (option) => {
|
|
204
|
+
const { path, title, description } = option;
|
|
205
|
+
return (Component) => {
|
|
206
|
+
if (!path)
|
|
207
|
+
throw new Error("You must provide a path to the page");
|
|
208
|
+
// Create a new instance of the component
|
|
209
|
+
const component = new Component();
|
|
210
|
+
// Set properties
|
|
211
|
+
component.path = path;
|
|
212
|
+
component.title = title || Component.name;
|
|
213
|
+
component.description = description || "";
|
|
214
|
+
return component;
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* This function adds metadata to a page or a layout
|
|
219
|
+
* @param option
|
|
220
|
+
* @returns
|
|
221
|
+
*/
|
|
222
|
+
export const defineRouteLayout = (option) => {
|
|
223
|
+
const { path } = option;
|
|
224
|
+
return (Component) => {
|
|
225
|
+
if (!path)
|
|
226
|
+
throw new Error("You must provide a path to the layout");
|
|
227
|
+
// Create a new instance of the component
|
|
228
|
+
const component = new Component();
|
|
229
|
+
// Set properties
|
|
230
|
+
component.path = path;
|
|
231
|
+
return component;
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* This function adds metadata to a router
|
|
236
|
+
* @param option
|
|
237
|
+
* @returns
|
|
238
|
+
*/
|
|
239
|
+
export const defineRouter = (option) => {
|
|
240
|
+
const { imports, layout, pages, loaderComponent, notFoundComponent } = option;
|
|
241
|
+
return (Component) => {
|
|
242
|
+
// Handle errors
|
|
243
|
+
if (!option.pages)
|
|
244
|
+
throw new Error("You must provide a list of pages in the router decorator");
|
|
245
|
+
// Create router
|
|
246
|
+
const router = new Component();
|
|
247
|
+
// Set properties
|
|
248
|
+
router.routers = imports || [];
|
|
249
|
+
router.layout = layout || new DefaultLayout();
|
|
250
|
+
router.pages = pages;
|
|
251
|
+
router.loaderComponent = loaderComponent || (() => null);
|
|
252
|
+
router.notFoundComponent = notFoundComponent || NotFoundPageComponent;
|
|
253
|
+
return router;
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/routing/utils/index.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAMvE,OAAO,EAAE,aAAa,EAAkC,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EACL,eAAe,EACf,0BAA0B,EAC1B,qBAAqB,EACrB,eAAe,GAChB,MAAM,wB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;IACnB,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAA4B,EAAE,EAAE;IAC3D,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAE9E,OAAO,CAAC,SAAoC,EAAE,EAAE;QAC9C,gBAAgB;QAChB,IAAI,CAAC,MAAM,CAAC,KAAK;YACf,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;QAEJ,gBAAgB;QAChB,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;QAE/B,iBAAiB;QACjB,MAAM,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;QAC/B,MAAM,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;QAC9C,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,MAAM,CAAC,eAAe,GAAG,eAAe,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;QACzD,MAAM,CAAC,iBAAiB,GAAG,iBAAiB,IAAI,qBAAqB,CAAC;QAEtE,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path, { join, dirname } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import { createStaticHandler, createStaticRouter, } from "react-router-dom/server.js";
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { createFetchRequest } from "rasengan";
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
// Create server for production only
|
|
10
|
+
export default async function handler(req, res) {
|
|
11
|
+
try {
|
|
12
|
+
// Get URL
|
|
13
|
+
const url = req.url;
|
|
14
|
+
const host = req.headers.host;
|
|
15
|
+
// Get app path
|
|
16
|
+
const appPath = join(__dirname, "..");
|
|
17
|
+
// ! Favicon Fix
|
|
18
|
+
if (url === "/favicon.ico") {
|
|
19
|
+
return res.send(path.resolve(join(appPath, "dist/client/rasengan.png")));
|
|
20
|
+
}
|
|
21
|
+
// ! Robots Fix
|
|
22
|
+
if (url === "/robots.txt") {
|
|
23
|
+
return res.send(`
|
|
24
|
+
user-agent: *
|
|
25
|
+
disallow: /downloads/
|
|
26
|
+
disallow: /private/
|
|
27
|
+
allow: /
|
|
28
|
+
|
|
29
|
+
user-agent: magicsearchbot
|
|
30
|
+
disallow: /uploads/
|
|
31
|
+
`);
|
|
32
|
+
}
|
|
33
|
+
// ! Sitemap Fix
|
|
34
|
+
if (url === "/sitemap.xml") {
|
|
35
|
+
return res.send(path.resolve(join(appPath, "dist/client/sitemap.xml")));
|
|
36
|
+
}
|
|
37
|
+
// ! Manifest Fix
|
|
38
|
+
if (url === "/manifest.json") {
|
|
39
|
+
return res.send(path.resolve(join(appPath, "dist/client/manifest.json")));
|
|
40
|
+
}
|
|
41
|
+
let template;
|
|
42
|
+
let entry;
|
|
43
|
+
let manifest;
|
|
44
|
+
// Always read fresh template in development
|
|
45
|
+
const htmlFilePath = join(appPath, "dist/client/index.html");
|
|
46
|
+
const serverFilePath = join(appPath, "dist/server/entry-server.js");
|
|
47
|
+
const ssrManifestFilePath = join(appPath, "dist/client/.vite/ssr-manifest.json");
|
|
48
|
+
// Read template, server-renderer and manifest in production
|
|
49
|
+
template = await fs.readFile(htmlFilePath, "utf-8");
|
|
50
|
+
entry = await import(serverFilePath);
|
|
51
|
+
manifest = await fs.readFile(ssrManifestFilePath, "utf-8");
|
|
52
|
+
// Extract render and staticRoutes from entry
|
|
53
|
+
const { render, staticRoutes } = entry;
|
|
54
|
+
// Create static handler
|
|
55
|
+
let handler = createStaticHandler(staticRoutes);
|
|
56
|
+
// Create fetch request for static routing
|
|
57
|
+
let fetchRequest = createFetchRequest(req, host);
|
|
58
|
+
let context = await handler.query(fetchRequest);
|
|
59
|
+
// Handle redirects
|
|
60
|
+
const status = context.status;
|
|
61
|
+
if (status === 302) {
|
|
62
|
+
const redirect = context.headers.get("Location");
|
|
63
|
+
if (redirect)
|
|
64
|
+
return res.redirect(redirect);
|
|
65
|
+
}
|
|
66
|
+
// Helmet context
|
|
67
|
+
const helmetContext = {};
|
|
68
|
+
// Create static router
|
|
69
|
+
let router = createStaticRouter(handler.dataRoutes, context);
|
|
70
|
+
const rendered = await render(router, context, helmetContext);
|
|
71
|
+
// Get metadata
|
|
72
|
+
const helmet = helmetContext.helmet;
|
|
73
|
+
let head = `
|
|
74
|
+
${helmet.title.toString()}
|
|
75
|
+
${helmet.meta.toString()}
|
|
76
|
+
`;
|
|
77
|
+
let html = template
|
|
78
|
+
.replace(`<!--app-head-->`, head ?? "")
|
|
79
|
+
.replace(`<!--app-html-->`, rendered.html ?? "");
|
|
80
|
+
res
|
|
81
|
+
.status(200)
|
|
82
|
+
.setHeader("Content-Type", "text/html")
|
|
83
|
+
.setHeader("Cache-Control", "max-age=31536000")
|
|
84
|
+
.end(html);
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
console.log(e.stack);
|
|
88
|
+
res.status(500).end(e.stack);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/server/functions/vercel/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAEL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,aAAa;AACb,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,C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AAE,aAAa,CAAC,CAAC;QAE9D,eAAe;QACf,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;QAEpC,IAAI,IAAI,GAAG;QACP,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE;QACvB,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE;KACzB,CAAC;QAEF,IAAI,IAAI,GAAG,QAAQ;aAChB,OAAO,CAAC,iBAAiB,EAAE,IAAI,IAAI,EAAE,CAAC;aACtC,OAAO,CAAC,iBAAiB,EAAE,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QAEnD,GAAG;aACA,MAAM,CAAC,GAAG,CAAC;aACX,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC;aACtC,SAAS,CAAC,eAAe,EAAE,kBAAkB,CAAC;aAC9C,GAAG,CAAC,IAAI,CAAC,CAAC;IACf,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACrB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function is used to create a fetch request from an express request.
|
|
3
|
+
*/
|
|
4
|
+
export default function createFetchRequest(req, host) {
|
|
5
|
+
let origin = `${req.protocol}://${host}`;
|
|
6
|
+
// Note: This had to take originalUrl into account for presumably vite's proxying
|
|
7
|
+
let url = new URL(req.originalUrl || req.url, origin);
|
|
8
|
+
let controller = new AbortController();
|
|
9
|
+
req.on("close", () => controller.abort());
|
|
10
|
+
let headers = new Headers();
|
|
11
|
+
for (let [key, values] of Object.entries(req.headers)) {
|
|
12
|
+
if (values) {
|
|
13
|
+
if (Array.isArray(values)) {
|
|
14
|
+
for (let value of values) {
|
|
15
|
+
headers.append(key, value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
headers.set(key, values);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
let init = {
|
|
24
|
+
method: req.method,
|
|
25
|
+
headers,
|
|
26
|
+
signal: controller.signal,
|
|
27
|
+
body: null,
|
|
28
|
+
};
|
|
29
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
30
|
+
init.body = req.body;
|
|
31
|
+
}
|
|
32
|
+
return new Request(url.href, init);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=createFetchRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFetchRequest.js","sourceRoot":"","sources":["../../../src/server/utils/createFetchRequest.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,GAAY,EAAE,IAAY;IACnE,IAAI,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,MAAM,IAAI,EAAE,CAAC;IACzC,iFAAiF;IACjF,IAAI,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAEtD,IAAI,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACvC,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;IAE1C,IAAI,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAE5B,KAAK,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QACtD,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC1B,KAAK,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC;oBACzB,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;gBAC7B,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,IAAI,GAAG;QACT,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,OAAO;QACP,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,IAAI,EAAE,IAAI;KACX,CAAC;IAEF,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAClD,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IACvB,CAAC;IAED,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function getIP(): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
// Get local IP
|
|
3
|
+
export default function getIP() {
|
|
4
|
+
// Get network interfaces
|
|
5
|
+
const networkInterfaces = os.networkInterfaces();
|
|
6
|
+
// Find the IPv4 address for the default network interface
|
|
7
|
+
let ipAddress = "";
|
|
8
|
+
// Loop through the network interfaces
|
|
9
|
+
for (const interfaceName in networkInterfaces) {
|
|
10
|
+
// Get the network interface
|
|
11
|
+
const iface = networkInterfaces[interfaceName];
|
|
12
|
+
// Skip when there is no network interface
|
|
13
|
+
if (!iface) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
// Loop through the interface addresses
|
|
17
|
+
for (let i = 0; i < iface.length; i++) {
|
|
18
|
+
const alias = iface[i];
|
|
19
|
+
if (alias.family === "IPv4" && !alias.internal) {
|
|
20
|
+
ipAddress = alias.address;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (ipAddress) {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return ipAddress;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=getIp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getIp.js","sourceRoot":"","sources":["../../../src/server/utils/getIp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,eAAe;AACf,MAAM,CAAC,OAAO,UAAU,KAAK;IAC3B,yBAAyB;IACzB,MAAM,iBAAiB,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAC;IAEjD,0DAA0D;IAC1D,IAAI,SAAS,GAAG,EAAE,CAAC;IAEnB,sCAAsC;IACtC,KAAK,MAAM,aAAa,IAAI,iBAAiB,EAAE,CAAC;QAC9C,4BAA4B;QAC5B,MAAM,KAAK,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC;QAE/C,0CAA0C;QAC1C,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,SAAS;QACX,CAAC;QAED,uCAAuC;QACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YAEvB,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;gBAC/C,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC;gBAC1B,MAAM;YACR,CAAC;QACH,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACd,MAAM;QACR,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import path, { join } from "node:path";
|
|
2
|
+
export function fix404(url, res, appPath) {
|
|
3
|
+
// ! Favicon Fix
|
|
4
|
+
if (url === "/favicon.ico") {
|
|
5
|
+
return res.sendFile(path.resolve(join(appPath, "dist/client/rasengan.png")));
|
|
6
|
+
}
|
|
7
|
+
// ! Robots Fix
|
|
8
|
+
if (url === "/robots.txt") {
|
|
9
|
+
return res.send(`
|
|
10
|
+
user-agent: *
|
|
11
|
+
disallow: /downloads/
|
|
12
|
+
disallow: /private/
|
|
13
|
+
allow: /
|
|
14
|
+
|
|
15
|
+
user-agent: magicsearchbot
|
|
16
|
+
disallow: /uploads/
|
|
17
|
+
`);
|
|
18
|
+
}
|
|
19
|
+
// ! Sitemap Fix
|
|
20
|
+
if (url === "/sitemap.xml") {
|
|
21
|
+
return res.sendFile(path.resolve(join(appPath, "dist/client/sitemap.xml")));
|
|
22
|
+
}
|
|
23
|
+
// ! Manifest Fix
|
|
24
|
+
if (url === "/manifest.json") {
|
|
25
|
+
return res.sendFile(path.resolve(join(appPath, "dist/client/manifest.json")));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=handleError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleError.js","sourceRoot":"","sources":["../../../src/server/utils/handleError.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGvC,MAAM,UAAU,MAAM,CAAC,GAAW,EAAE,GAAa,EAAE,OAAe;IAChE,gBAAgB;IAChB,IAAI,GAAG,KAAK,cAAc,EAAE,CAAC;QAC3B,OAAO,GAAG,CAAC,QAAQ,CACjB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,0BAA0B,CAAC,CAAC,CACxD,CAAC;IACJ,CAAC;IAED,eAAe;IACf,IAAI,GAAG,KAAK,aAAa,EAAE,CAAC;QAC1B,OAAO,GAAG,CAAC,IAAI,CAAC;;;;;;;;KAQf,CAAC,CAAC;IACL,CAAC;IAED,gBAAgB;IAChB,IAAI,GAAG,KAAK,cAAc,EAAE,CAAC;QAC3B,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,yBAAyB,CAAC,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,iBAAiB;IACjB,IAAI,GAAG,KAAK,gBAAgB,EAAE,CAAC;QAC7B,OAAO,GAAG,CAAC,QAAQ,CACjB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,2BAA2B,CAAC,CAAC,CACzD,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Import section
|
|
2
|
+
import createFetchRequest from "./createFetchRequest.js";
|
|
3
|
+
import getIP from "./getIp.js";
|
|
4
|
+
import { logServerInfo } from "./log.js";
|
|
5
|
+
import { fix404 } from "./handleError.js";
|
|
6
|
+
// Export section
|
|
7
|
+
export { createFetchRequest, getIP, logServerInfo, fix404, };
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/utils/index.ts"],"names":[],"mappings":"AAAA,iBAAiB;AAEjB,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,iBAAiB;AAEjB,OAAO,EACL,kBAAkB,EAClB,KAAK,EACL,aAAa,EACb,MAAM,GACP,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log server info after the server is started
|
|
3
|
+
* @param {number} port The port the server is running on
|
|
4
|
+
* @param {boolean} isProduction Whether the server is running in production mode
|
|
5
|
+
*/
|
|
6
|
+
export declare function logServerInfo(port: number, isProduction: boolean): Promise<void>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import fs from "fs/promises";
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import keypress from "keypress";
|
|
6
|
+
import { getIP } from "./index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Log server info after the server is started
|
|
9
|
+
* @param {number} port The port the server is running on
|
|
10
|
+
* @param {boolean} isProduction Whether the server is running in production mode
|
|
11
|
+
*/
|
|
12
|
+
export async function logServerInfo(port, isProduction) {
|
|
13
|
+
// Constants
|
|
14
|
+
const arrowRight = "\u2192";
|
|
15
|
+
// Spinner
|
|
16
|
+
console.log("");
|
|
17
|
+
const spinner = ora({
|
|
18
|
+
text: `Starting server in ${isProduction ? "production" : "development"} mode...`,
|
|
19
|
+
color: "blue",
|
|
20
|
+
spinner: "dots",
|
|
21
|
+
}).start();
|
|
22
|
+
// Getting the package.json file
|
|
23
|
+
let packageJson;
|
|
24
|
+
if (!isProduction) {
|
|
25
|
+
packageJson = await fs.readFile("node_modules/rasengan/package.json", "utf-8");
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
packageJson = await fs.readFile("package.json", "utf-8");
|
|
29
|
+
}
|
|
30
|
+
// Parsing the package.json file
|
|
31
|
+
const parsedPackageJson = JSON.parse(packageJson);
|
|
32
|
+
spinner.succeed(`${chalk.bold.blue(`Rasengan v${parsedPackageJson["version"]}`)} is running 🚀`);
|
|
33
|
+
console.log("\n\n");
|
|
34
|
+
process.stdout.write(`${chalk.bold.green(arrowRight)} ${chalk.bold("Local:")} ${chalk.blue(`http://localhost:${chalk.bold(port)}`)}`);
|
|
35
|
+
console.log("");
|
|
36
|
+
// Get the IP address of the machine
|
|
37
|
+
const ipAddress = getIP();
|
|
38
|
+
if (ipAddress) {
|
|
39
|
+
process.stdout.write(`${chalk.bold.green(arrowRight)} ${chalk.bold("Network:")} ${chalk.blue(`http://${getIP()}:${chalk.bold(port)}`)}\n`);
|
|
40
|
+
}
|
|
41
|
+
// Display options
|
|
42
|
+
process.stdout.write(`${chalk.bold.green(arrowRight)} ${chalk.gray("Use")} ${chalk.bold("-p <PORT>")} ${chalk.gray("to specify a custom port")}\n`);
|
|
43
|
+
process.stdout.write(`${chalk.bold.green(arrowRight)} ${chalk.gray("Press")} ${chalk.bold("c")} ${chalk.gray("to clear")}\n`);
|
|
44
|
+
process.stdout.write(`${chalk.bold.green(arrowRight)} ${chalk.gray("Press")} ${chalk.bold("ctrl + c")} ${chalk.gray("to close the server")}\n`);
|
|
45
|
+
console.log("\n");
|
|
46
|
+
// Enable keypress events on the process.stdin stream
|
|
47
|
+
keypress(process.stdin);
|
|
48
|
+
// Listen on user keyboard input on the terminal
|
|
49
|
+
process.stdin.on("keypress", (_, key) => {
|
|
50
|
+
// Check if the key pressed is 'c'
|
|
51
|
+
if (key) {
|
|
52
|
+
if (key.name === "c" && key.ctrl) {
|
|
53
|
+
console.log(`${chalk.green("ctrl + c")} ${chalk.gray("pressed: ")} ${chalk.blue("Closing server... \n\n")}`);
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
else if (key.name === "c" && !key.ctrl && !key.meta && !key.shift) {
|
|
57
|
+
// Clear terminal
|
|
58
|
+
process.stdout.write("\x1Bc");
|
|
59
|
+
logServerInfo(port, isProduction);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
// Allow the process to exit when Ctrl+C is pressed
|
|
64
|
+
process.stdin.setRawMode(true);
|
|
65
|
+
process.stdin.resume();
|
|
66
|
+
// Set a higher limit for the number of listeners
|
|
67
|
+
process.stdin.setMaxListeners(100);
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../../src/server/utils/log.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,aAAa;AACb,OAAO,QA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