- Aggiornato node.js alla versione 22.18.1
- Aggiornato tutti i pacchetti del server all'ultima versione. - passato mongoose da versione 5 a versione 6
This commit is contained in:
@@ -2,7 +2,12 @@ require('./config/config');
|
||||
|
||||
// console.log(" lodash");
|
||||
|
||||
console.log(process.versions);
|
||||
console.log("VERSIONE MODULI:", process.versions);
|
||||
if (process.env.AUTH_MONGODB === undefined) {
|
||||
console.error("AUTH_MONGODB non presente. VARIABILI D'AMBIENTE NON SETTATI!");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
const _ = require('lodash');
|
||||
// console.log(" cors");
|
||||
@@ -212,15 +217,6 @@ myLoad().then(ris => {
|
||||
|
||||
}
|
||||
|
||||
// require('./telegram/telegrambot');
|
||||
|
||||
// *** DB CONNECTIONS ***
|
||||
// mysql_func.mySqlConn_Shen.connect((err) => {
|
||||
// if (!err)
|
||||
// console.log('DB connection to Shen Database succeded.');
|
||||
// else
|
||||
// console.log('DB connection to Shen Database FAILED \n Error: ' + JSON.stringify(err, undefined, 2));
|
||||
// });
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
console.log('*** PRODUCTION! ');
|
||||
@@ -804,7 +800,6 @@ function startServer(app, port) {
|
||||
|
||||
console.log('isProduction', isProduction);
|
||||
|
||||
|
||||
const NOCORS = false;
|
||||
const CORS_ENABLE_FOR_ALL_SITES = false;
|
||||
|
||||
@@ -813,38 +808,46 @@ function startServer(app, port) {
|
||||
let corsOptions = {};
|
||||
|
||||
if (NOCORS) {
|
||||
console.log('NOCORS')
|
||||
corsOptions = {
|
||||
exposedHeaders: ['x-auth', 'x-refrtok'], // Intestazioni da esporre al client
|
||||
};
|
||||
|
||||
} else {
|
||||
console.log('WITH CORS')
|
||||
let myorigin = '*';
|
||||
let credentials = false;
|
||||
|
||||
// Configurazione CORS dettagliata
|
||||
const corsOptions = {
|
||||
origin: '*',
|
||||
const allowedOrigins = domains.flatMap(domain => [
|
||||
`https://${domain.hostname}`,
|
||||
`https://api.${domain.hostname}`,
|
||||
`https://test.${domain.hostname}`,
|
||||
`https://testapi.${domain.hostname}`,
|
||||
`http://${domain.hostname}`,
|
||||
`http://api.${domain.hostname}`,
|
||||
`http://test.${domain.hostname}`,
|
||||
`http://testapi.${domain.hostname}`
|
||||
]);
|
||||
|
||||
/*origin: function (origin, callback) {
|
||||
if (domains.length > 0) {
|
||||
myorigin = function (origin, callback) {
|
||||
// Array di domini consentiti
|
||||
const allowedOrigins = [
|
||||
'https://comunitanuovomondo.app',
|
||||
'https://kolibrilab.it',
|
||||
'https://riso.app',
|
||||
'https://api.riso.app',
|
||||
'https://test.riso.app',
|
||||
'https://testapi.riso.app',
|
||||
'http://localhost:8080', // per sviluppo locale
|
||||
'http://localhost:3000',
|
||||
'http://localhost:8084',
|
||||
];
|
||||
|
||||
|
||||
// console.log('allowedOrigins', allowedOrigins);
|
||||
|
||||
// Permetti richieste senza origin (es. mobile apps)
|
||||
if (!origin || allowedOrigins.includes(origin)) {
|
||||
callback(null, true);
|
||||
} else {
|
||||
callback(new Error('❌ CORS non permesso per questa origine'));
|
||||
}
|
||||
},*/
|
||||
credentials: false,
|
||||
}
|
||||
}
|
||||
|
||||
// Configurazione CORS dettagliata
|
||||
const corsOptions = {
|
||||
origin: myorigin,
|
||||
credentials,
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH'],
|
||||
allowedHeaders: [
|
||||
'Origin',
|
||||
@@ -868,7 +871,7 @@ function startServer(app, port) {
|
||||
app.use(express.json()); // Middleware per il parsing del corpo JSON
|
||||
|
||||
// Gestione specifica delle richieste OPTIONS
|
||||
app.options('*', function (req, res) {
|
||||
/* app.options('*', function (req, res) {
|
||||
const origin = req.headers.origin;
|
||||
if (corsOptions.origin === '*' ||
|
||||
(typeof corsOptions.origin === 'function' &&
|
||||
@@ -886,7 +889,7 @@ function startServer(app, port) {
|
||||
} else {
|
||||
res.status(403).end();
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
// Middleware per assicurarsi che gli headers CORS siano sempre presenti
|
||||
app.use((req, res, next) => {
|
||||
|
||||
Reference in New Issue
Block a user