backend-plus 2.5.2-betha.16 → 2.5.2-betha.18
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/lib/backend-plus.d.ts +2 -1
- package/lib/backend-plus.js +17 -12
- package/package.json +1 -1
package/lib/backend-plus.d.ts
CHANGED
|
@@ -396,7 +396,8 @@ export interface AppConfigServer
|
|
|
396
396
|
"kill-9": string // a way to kill from URL with a token
|
|
397
397
|
bitacoraSchema: string
|
|
398
398
|
bitacoraTableName: string
|
|
399
|
-
|
|
399
|
+
useCors: boolean //habilita Cross-Origin Resource Sharing
|
|
400
|
+
allowedHosts:string[] //determina API allowed hosts (necesita habilitar useCors)
|
|
400
401
|
}
|
|
401
402
|
export interface AppConfigDb
|
|
402
403
|
{
|
package/lib/backend-plus.js
CHANGED
|
@@ -913,18 +913,23 @@ AppBackend.prototype.start = function start(opts){
|
|
|
913
913
|
}).then(async function(){
|
|
914
914
|
mainApp = express();
|
|
915
915
|
//mainApp.use(cookieParser());
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
916
|
+
if(be.config.server.allowedHosts){
|
|
917
|
+
if(!Array.isArray(be.config.server.allowedHosts)){
|
|
918
|
+
throw Error('allowedHosts must be an Array')
|
|
919
|
+
}
|
|
920
|
+
const whitelist = ['localhost'].concat(be.config.server.allowedHosts);
|
|
921
|
+
const corsOptions = {
|
|
922
|
+
origin: function (origin, callback) {
|
|
923
|
+
if (whitelist.some((element)=>origin?.includes(element)) || !origin){
|
|
924
|
+
callback(null, true);
|
|
925
|
+
}else{
|
|
926
|
+
callback(new Error('Not allowed by CORS'));
|
|
927
|
+
}
|
|
928
|
+
},
|
|
929
|
+
credentials: true
|
|
930
|
+
};
|
|
931
|
+
mainApp.use(cors(corsOptions));
|
|
932
|
+
}
|
|
928
933
|
mainApp.use(bodyParser.urlencoded({extended:true, limit: '50mb'}));
|
|
929
934
|
mainApp.use(function(req,res,next){
|
|
930
935
|
if((req.headers['content-type']||'').match(/^multipart\/form-data/)){
|
package/package.json
CHANGED