frosty 0.0.81 → 0.0.83
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/package.json
CHANGED
|
@@ -28,14 +28,10 @@ import fs from 'fs';
|
|
|
28
28
|
import path from 'path';
|
|
29
29
|
import { Server } from '@o2ter/server-js';
|
|
30
30
|
import { ReactRoute } from './route';
|
|
31
|
+
import __SERVER__ from '__SERVER__';
|
|
31
32
|
import * as __APPLICATIONS__ from '__APPLICATIONS__';
|
|
32
33
|
import { PORT } from './env';
|
|
33
34
|
|
|
34
|
-
let __SERVER__ = {};
|
|
35
|
-
try {
|
|
36
|
-
__SERVER__ = await import('__SERVER__');
|
|
37
|
-
} catch {};
|
|
38
|
-
|
|
39
35
|
const app = 'serverOptions' in __SERVER__ ? new Server(__SERVER__.serverOptions) : new Server;
|
|
40
36
|
|
|
41
37
|
app.use(Server.static(path.join(__dirname, 'public'), { cacheControl: true }));
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
import _ from 'lodash';
|
|
27
27
|
import { ServerDOMRenderer } from 'frosty/server-dom';
|
|
28
|
-
import { JSDOM, CookieJar } from 'jsdom';
|
|
28
|
+
import { JSDOM, CookieJar, ResourceLoader } from 'jsdom';
|
|
29
29
|
|
|
30
30
|
export const renderToHTML = async (App, {
|
|
31
31
|
request: req,
|
|
@@ -33,12 +33,15 @@ export const renderToHTML = async (App, {
|
|
|
33
33
|
jsSrc,
|
|
34
34
|
cssSrc,
|
|
35
35
|
}) => {
|
|
36
|
+
const referrer = req.get('Referrer');
|
|
37
|
+
const userAgent = req.get('User-Agent');
|
|
36
38
|
const url = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
|
|
37
39
|
const cookieJar = new CookieJar();
|
|
38
40
|
for (const cookie of _.split(req.get('cookie'), ';')) {
|
|
39
41
|
cookieJar.setCookieSync(cookie, url);
|
|
40
42
|
}
|
|
41
|
-
const
|
|
43
|
+
const loader = new ResourceLoader({ userAgent });
|
|
44
|
+
const dom = new JSDOM(undefined, { url, referrer, userAgent, resources: loader, cookieJar });
|
|
42
45
|
const renderer = new ServerDOMRenderer(dom);
|
|
43
46
|
res.setHeader('Content-Type', 'text/html');
|
|
44
47
|
res.send(await renderer.renderToString(
|
|
@@ -44,13 +44,10 @@ export default async (env, argv) => {
|
|
|
44
44
|
} = env;
|
|
45
45
|
|
|
46
46
|
const serverConfig = await (async () => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
console.log(e);
|
|
52
|
-
return {};
|
|
53
|
-
}
|
|
47
|
+
const configPath = path.resolve(process.cwd(), CONFIG_FILE);
|
|
48
|
+
if (!fs.existsSync(configPath)) return {};
|
|
49
|
+
const { default: resolved } = await import(configPath);
|
|
50
|
+
return resolved;
|
|
54
51
|
})();
|
|
55
52
|
|
|
56
53
|
const config = _.isFunction(serverConfig) ? serverConfig(env, argv) : serverConfig;
|
|
@@ -201,7 +198,7 @@ export default async (env, argv) => {
|
|
|
201
198
|
...config.options?.plugins ?? [],
|
|
202
199
|
];
|
|
203
200
|
|
|
204
|
-
const server = config.serverEntry ? path.resolve(process.cwd(), config.serverEntry) : path.resolve(__dirname, './src/server/default.
|
|
201
|
+
const server = config.serverEntry ? path.resolve(process.cwd(), config.serverEntry) : path.resolve(__dirname, './src/server/default.ts');
|
|
205
202
|
|
|
206
203
|
const random = crypto.randomUUID();
|
|
207
204
|
const tempDir = fs.mkdtempSync(`${os.tmpdir()}${path.sep}`);
|