manage Buffer in node.js and add suggestedalias in get alias
This commit is contained in:
@@ -1,3 +1,23 @@
|
|||||||
|
// CRITICAL FIX: Ensure Buffer is available globally before ANY modules load
|
||||||
|
// This fixes the "Cannot read properties of undefined (reading 'prototype')" error
|
||||||
|
if (typeof global !== 'undefined') {
|
||||||
|
// Force load buffer module and make it globally available
|
||||||
|
const buffer = require('buffer');
|
||||||
|
if (!global.Buffer) {
|
||||||
|
global.Buffer = buffer.Buffer;
|
||||||
|
}
|
||||||
|
// Also ensure it's available in this scope
|
||||||
|
if (typeof Buffer === 'undefined') {
|
||||||
|
global.Buffer = buffer.Buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Double-check Buffer is available
|
||||||
|
if (typeof Buffer === 'undefined') {
|
||||||
|
console.error('ERROR: Buffer is still undefined!');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
//const { argv } = require("process");
|
//const { argv } = require("process");
|
||||||
const fs = require("fs-extra");
|
const fs = require("fs-extra");
|
||||||
const bodyParser = require("body-parser");
|
const bodyParser = require("body-parser");
|
||||||
@@ -291,7 +311,30 @@ apxtri.runexpress = async (tribesdns, conf) => {
|
|||||||
regtxt += ")$";
|
regtxt += ")$";
|
||||||
// let cor = false;whatwg-url
|
// let cor = false;whatwg-url
|
||||||
const regorigin = new RegExp(regtxt);
|
const regorigin = new RegExp(regtxt);
|
||||||
app.use((req, res, next) => {
|
app.use(cors({
|
||||||
|
origin: function (origin, callback) {
|
||||||
|
// Allow requests with no origin (like mobile apps, curl, etc.)
|
||||||
|
if (!origin) {
|
||||||
|
return callback(null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if origin matches allowed domains pattern
|
||||||
|
if (regorigin.test(origin)) {
|
||||||
|
return callback(null, true);
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
`CORS blocked: ${origin} does not match pattern ${regtxt}. Add it in itm/tribename.json in dns.`
|
||||||
|
);
|
||||||
|
return callback(new Error('Not allowed by CORS'));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
allowedHeaders: conf.api.exposedHeaders,
|
||||||
|
exposedHeaders: conf.api.exposedHeaders,
|
||||||
|
credentials: true,
|
||||||
|
preflightContinue: false,
|
||||||
|
optionsSuccessStatus: 204,
|
||||||
|
}));
|
||||||
|
/*app.use((req, res, next) => {
|
||||||
let cor = false;
|
let cor = false;
|
||||||
//console.log(req.headers)
|
//console.log(req.headers)
|
||||||
if (req.headers.origin == undefined) {
|
if (req.headers.origin == undefined) {
|
||||||
@@ -314,7 +357,7 @@ apxtri.runexpress = async (tribesdns, conf) => {
|
|||||||
});
|
});
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
// Routers add any routes from /routes and /plugins
|
// Routers add any routes from /routes and /plugins
|
||||||
let logroute = "Routes available on this apxtri instance: \n";
|
let logroute = "Routes available on this apxtri instance: \n";
|
||||||
routes.forEach((r) => {
|
routes.forEach((r) => {
|
||||||
|
|||||||
@@ -143,12 +143,25 @@ Pagans.getalias = (alias) => {
|
|||||||
data: fs.readJSONSync(`../adminapi/objects/pagans/itm/${alias}.json`),
|
data: fs.readJSONSync(`../adminapi/objects/pagans/itm/${alias}.json`),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
try{
|
||||||
|
const lst_alias=fs.readJSONSync(`../adminapi/objects/pagans/idx/lst_alias.json`)
|
||||||
|
let suggestedalias=[]
|
||||||
|
let counter = 1;
|
||||||
|
while (suggestedalias.length < 3){
|
||||||
|
const candidate = `${alias}${counter}`;
|
||||||
|
if (!lst_alias.includes(candidate)){
|
||||||
|
suggestedalias.push(candidate)
|
||||||
|
}
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
status: 404,
|
status: 404,
|
||||||
ref: "Pagans",
|
ref: "Pagans",
|
||||||
msg: "aliasdoesnotexist",
|
msg: "aliasdoesnotexist",
|
||||||
data: { alias },
|
data: { alias, suggestedalias },
|
||||||
};
|
};
|
||||||
|
} catch(err){
|
||||||
|
return {status:500,msg:"lst_aliaserror",ref:"Pagans",data:{}}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user