admin管理员组文章数量:1187337
In a dev client/server deployment, my client is unable to request anything from the server, failing with a 401 unauthorized. The prod deployment is configured the same, and works just fine, so I wonder if this points to a server configuration issue, but regardless:
The issue is that, since this dev server deployment goes to a non-static base URL, I use a regex pattern match to check the URL, like so:
const app = express();
// cors
const corsOptions: CorsOptions = {
origin: (origin, callback) => {
const valid =
!origin ||
(CLIENT_URL
? CLIENT_URL === origin
: new RegExp(CLIENT_URL_PATTERN).test(origin));
callback(
valid
? null
: new Error(
`Unsupported cross-origin request from ${origin} using pattern ${CLIENT_URL_PATTERN}`,
),
valid,
);
},
allowedHeaders: [
'X-CSRF-Token',
'X-Requested-With',
'Accept',
'Accept-Version',
'Content-Length',
'Content - MD5',
'Content - Type',
'Date',
'X - Api - Version',
],
methods: ['GET', 'OPTIONS', 'PATCH', 'DELETE', 'POST', 'PUT'],
credentials: true,
};
app.options('*', cors(corsOptions));
app.use(cors(corsOptions));
Even with app.options('*', cors())
it still fails. Every request fails on preflight and they don't even pass through the origin callback for me to log anything. I'm stumped, and need some direction on where to look next.
本文标签: typescriptexpress preflight OPTIONS request fails with 401Stack Overflow
版权声明:本文标题:typescript - express preflight OPTIONS request fails with 401 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738367021a2081805.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论