spa-ssi 0.0.15 → 0.0.17
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 +1 -1
- package/serve.js +13 -14
package/package.json
CHANGED
package/serve.js
CHANGED
|
@@ -291,22 +291,21 @@ class SimpleHTTPRequestHandler {
|
|
|
291
291
|
let match;
|
|
292
292
|
while ((match = includeRegex.exec(html)) !== null) {
|
|
293
293
|
const includeString = match[1];
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
const content = await fs.readFile(includePath, 'utf8');
|
|
307
|
-
html = html.replace(match[0], content);
|
|
294
|
+
try{
|
|
295
|
+
const includePath = includeString.startsWith('/') ? path.join(process.cwd(), includeString) : path.join(currentDir, includeString);
|
|
296
|
+
const content = await fs.readFile(includePath, 'utf8');
|
|
297
|
+
html = html.replace(match[0], content);
|
|
298
|
+
}catch(e){
|
|
299
|
+
const includeMJSPath = `../../${includeString.replace('.html', '.mjs')}`;
|
|
300
|
+
const test = await import(includeMJSPath);
|
|
301
|
+
if(test.render && typeof test.render === 'function'){
|
|
302
|
+
const renderedContent = test.render();
|
|
303
|
+
html = html.replace(match[0], renderedContent);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
308
306
|
}
|
|
309
307
|
|
|
308
|
+
|
|
310
309
|
|
|
311
310
|
}
|
|
312
311
|
|