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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/serve.js +13 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spa-ssi",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "Single Page App / Server Side Include Simple File Web Server",
5
5
  "keywords": [
6
6
  "single-page-app",
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
- if(includeString.endsWith('.mjs')){
295
- // Dynamic import
296
- //const resolvedFilePath = path.join(process.cwd(), includeString);
297
- //console.log(`Including JS module: ${resolvedFilePath}`);
298
- const test = await import(includeString);
299
- if(test.render && typeof test.render === 'function'){
300
- const renderedContent = test.render();
301
- html = html.replace(match[0], renderedContent);
302
- continue;
303
- }
304
- }else{
305
- const includePath = includeString.startsWith('/') ? path.join(process.cwd(), includeString) : path.join(currentDir, includeString);
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