allow port in cors
This commit is contained in:
@@ -322,13 +322,16 @@ 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);
|
||||||
|
const allowedOrigins = [
|
||||||
|
'http://dev.smatchit.io:8081',
|
||||||
|
];
|
||||||
app.use(cors({
|
app.use(cors({
|
||||||
origin: function (origin, callback) {
|
origin: function (origin, callback) {
|
||||||
if (!origin) {
|
if (!origin) {
|
||||||
return callback(null, true);
|
return callback(null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (regorigin.test(origin)) {
|
if (regorigin.test(origin) || allowedOrigins.includes(origin)) {
|
||||||
return callback(null, true);
|
return callback(null, true);
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -346,7 +349,7 @@ apxtri.runexpress = async (tribesdns, conf) => {
|
|||||||
|
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
const origin = req.headers.origin;
|
const origin = req.headers.origin;
|
||||||
if (origin && !regorigin.test(origin)) {
|
if (origin && !regorigin.test(origin) && !allowedOrigins.includes(origin)) {
|
||||||
console.log(`CORS blocked: ${origin}`);
|
console.log(`CORS blocked: ${origin}`);
|
||||||
return res.status(403).json({ error: 'CORS not allowed', origin });
|
return res.status(403).json({ error: 'CORS not allowed', origin });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user