@ejfdelgado/ejflab-back 1.27.0 → 1.27.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/package.json +1 -1
- package/srv/MainHandler.mjs +45 -27
- package/srv/MyPdf.mjs +1 -0
package/package.json
CHANGED
package/srv/MainHandler.mjs
CHANGED
@@ -10,7 +10,8 @@ import { ModuloDatoSeguroBack } from "@ejfdelgado/ejflab-common/src/ModuloDatoSe
|
|
10
10
|
import { MyConstants } from "@ejfdelgado/ejflab-common/src/MyConstants.js";
|
11
11
|
|
12
12
|
export class MainHandler {
|
13
|
-
static
|
13
|
+
static LOCAL_FOLDER1 = path.resolve() + "/src";// First try
|
14
|
+
static LOCAL_FOLDER = path.resolve() + "/dist/bundle";// Finall try
|
14
15
|
static async handle(req, res, next) {
|
15
16
|
const originalUrl = req.getUrl();
|
16
17
|
const theUrl = url.parse(originalUrl);
|
@@ -97,37 +98,54 @@ export class MainHandler {
|
|
97
98
|
return null;
|
98
99
|
}
|
99
100
|
|
100
|
-
static async resolveLocalFileSingle(filename, encoding, rootFolder
|
101
|
+
static async resolveLocalFileSingle(filename, encoding, rootFolder) {
|
101
102
|
return new Promise((resolve, reject) => {
|
102
|
-
const somePath = path.join(rootFolder, filename);
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
104
|
+
// Try
|
105
|
+
const options = [];
|
106
|
+
if (rootFolder) {
|
107
|
+
options.push(path.join(rootFolder, filename));
|
108
|
+
}
|
109
|
+
options.push(path.join(MainHandler.LOCAL_FOLDER1, filename));
|
110
|
+
options.push(path.join(MainHandler.LOCAL_FOLDER, filename));
|
111
|
+
|
112
|
+
// Check which exists first, if not resolve null with log
|
113
|
+
let selected = null;
|
114
|
+
for (let i = 0; i < options.length; i++) {
|
115
|
+
const actual = options[i];
|
116
|
+
if (fs.existsSync(actual)) {
|
117
|
+
selected = actual;
|
118
|
+
break;
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
if (!selected) {
|
123
|
+
console.log(`Files not found ${options}`);
|
124
|
+
resolve(null);
|
125
|
+
}
|
126
|
+
|
127
|
+
const somePath = selected;
|
128
|
+
if (!fs.lstatSync(somePath).isFile()) {
|
129
|
+
resolve(null);
|
130
|
+
return;
|
131
|
+
}
|
132
|
+
if (typeof encoding == "string") {
|
133
|
+
fs.readFile(somePath, encoding, function (err, data) {
|
134
|
+
if (err) {
|
135
|
+
reject(err);
|
110
136
|
return;
|
111
137
|
}
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
});
|
120
|
-
} else {
|
121
|
-
fs.readFile(somePath, function (err, data) {
|
122
|
-
if (err) {
|
123
|
-
reject(err);
|
124
|
-
return;
|
125
|
-
}
|
126
|
-
resolve(data);
|
127
|
-
});
|
138
|
+
resolve(data);
|
139
|
+
});
|
140
|
+
} else {
|
141
|
+
fs.readFile(somePath, function (err, data) {
|
142
|
+
if (err) {
|
143
|
+
reject(err);
|
144
|
+
return;
|
128
145
|
}
|
129
|
-
|
130
|
-
|
146
|
+
resolve(data);
|
147
|
+
});
|
148
|
+
}
|
131
149
|
});
|
132
150
|
}
|
133
151
|
|