Skip to content

Commit

Permalink
Merge pull request #82 from core-ds/fix/dev-server-cors
Browse files Browse the repository at this point in the history
fix(dev-server-cors): add response for options method
  • Loading branch information
heymdall-legal authored Aug 14, 2023
2 parents a75a25b + 3617329 commit 9ab262a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-tables-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"arui-scripts": patch
---

Add 200 response for OPTIONS request when devServerCors option is enabled
21 changes: 14 additions & 7 deletions packages/arui-scripts/src/configs/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@ const devServerConfig = applyOverrides('devServer', {

return null;
},
// Для дев режима, когда мы используем в качестве соурсмапов что-то, основанное на eval - нужно
// разрешить браузеру исполнять наш код, даже когда content-security-policy приложения не позволяет этого делать.
...(configs.devSourceMaps.includes('eval') ? {
...(configs.devSourceMaps.includes('eval') || configs.devServerCors ? {
onProxyRes: (proxyRes: http.IncomingMessage) => {
const cspHeader = proxyRes.headers['content-security-policy'];
if (typeof cspHeader === 'string' && !cspHeader.includes('unsafe-eval')) {
proxyRes.headers['content-security-policy'] = cspHeader
.replace(/script-src/, 'script-src \'unsafe-eval\'');
// Для дев режима, когда мы используем в качестве соурсмапов что-то, основанное на eval - нужно
// разрешить браузеру исполнять наш код, даже когда content-security-policy приложения не позволяет этого делать.
if (configs.devSourceMaps.includes('eval')) {
const cspHeader = proxyRes.headers['content-security-policy'];
if (typeof cspHeader === 'string' && !cspHeader.includes('unsafe-eval')) {
proxyRes.headers['content-security-policy'] = cspHeader
.replace(/script-src/, 'script-src \'unsafe-eval\'');
}
}
// если включен devServerCors, то нужно принудительно менять статус ответа на 200, чтобы
// браузер не отклонял ответы с CORS
if (configs.devServerCors && proxyRes.method === 'OPTIONS') {
proxyRes.statusCode = 200;
}
},
} : {}),
Expand Down

0 comments on commit 9ab262a

Please sign in to comment.