binhend 2.1.30 → 2.1.32

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/demo.js CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
2
  const { HttpCodes, ConfigLoader, WebBuilder, HttpError, validation } = require('./index');
3
+ const path = require('path');
3
4
 
4
5
  // var jsonPath = __dirname + '/jsconfig.json';
5
6
  // var cc = ConfigLoader.json(jsonPath);
@@ -11,4 +12,6 @@ const loader = new ConfigLoader(config);
11
12
 
12
13
  loader.object({ foo: '1', koo: '2', hoo: '3' }, { filter: ['koo', 'hoo'] });
13
14
 
14
- console.log('config', config);
15
+ console.log('config', config);
16
+
17
+ console.log(path.resolve(__dirname, './app.secret'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binhend",
3
- "version": "2.1.30",
3
+ "version": "2.1.32",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
@@ -34,7 +34,10 @@ module.exports = (options) => {
34
34
  if (origin === undefined) return next();
35
35
 
36
36
  // Verify allowed origins
37
- const allowedOrigin = allowedOrigins.length === 0 || allowedOrigins.includes(origin) ? origin : '';
37
+ const acceptLocalhost = allowedOrigins.includes('localhost') && /^https{0,1}:\/\/localhost:\d+$/.test(origin);
38
+ const acceptOrigin = acceptLocalhost || allowedOrigins.length === 0 || allowedOrigins.includes(origin);
39
+ const allowedOrigin = acceptOrigin ? origin : '';
40
+
38
41
  res.header('Access-Control-Allow-Origin', allowedOrigin);
39
42
 
40
43
  if (!allowedOrigin) {
@@ -1,6 +1,6 @@
1
1
  const { config } = require('../configuration');
2
2
  const { readFileSync } = require('fs');
3
- const { parse } = require('path');
3
+ const { parseFileName } = require('./filename-parser');
4
4
  const { scanNestedFiles, cloneFileIfNew, printError, makeFullDirPath, writeToFileIfNew } = require('./component.file');
5
5
 
6
6
  const PREFIX_CODE =
@@ -23,25 +23,25 @@ function generate(sourceRootPath, outputRootPath, callbackDone) {
23
23
  try {
24
24
  makeFullDirPath(fileOutputPath);
25
25
 
26
- var fileExtension = parse(file.name).ext;
27
-
28
- if (fileExtension === '.css') {
26
+ var filename = parseFileName(file.name);
27
+
28
+ if (filename.ext === '.css') {
29
29
  var cssModuleCode = 'binh.css(module);';
30
30
  writeToFileIfNew(fileOutputPath + '.js', cssModuleCode);
31
31
  // not return here, but wait for next "if" statement to be copied to build folder, then return there.
32
32
  }
33
33
 
34
- if (fileExtension !== '.js' && fileExtension !== '.cjs' && fileExtension !== '.mjs') {
34
+ if (filename.ext !== '.js' && filename.ext !== '.cjs' && filename.ext !== '.mjs') {
35
35
  // any files not JS (.css, .jpg, etc.) will be copied to build folder.
36
36
  cloneFileIfNew(fileSourcePath, fileOutputPath);
37
37
  return;
38
38
  }
39
39
 
40
40
  var fileContent = readFileSync(fileSourcePath, { encoding: 'utf8', flag: 'r' });
41
- var formatCode = mapConfigValues(fileContent.trim()); // for .cjs (common js) and .mjs (module js) files, not build code but still bind config values
41
+ var formatCode = mapConfigValues(fileContent.trim()); // for .c.js files, not build code but still bind config values
42
42
 
43
- if (fileExtension === '.js') {
44
- // for .js files, build code and bind config values
43
+ if (filename.ext2 !== '.c.js') {
44
+ // except for .c.js files, build code and bind config values for other JS files (.js, .cjs, .mjs)
45
45
  formatCode = PREFIX_CODE + formatCode + '\r\n\r\n;binh.final(module);';
46
46
  }
47
47
 
@@ -0,0 +1,24 @@
1
+
2
+
3
+ const { parse } = require('path');
4
+
5
+ function parseFileName(filename) {
6
+ const parsed = parse(filename);
7
+ const segments = parsed.base.split('.');
8
+
9
+ var ext2 = parsed.ext;
10
+
11
+ if (segments.length >= 3) {
12
+ // last two segments form the level 2 extension
13
+ ext2 = '.' + segments.slice(-2).join('.');
14
+ }
15
+
16
+ return {
17
+ ...parsed,
18
+ ext2,
19
+ };
20
+ }
21
+
22
+ module.exports = {
23
+ parseFileName
24
+ };