Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CORS to CTA #213

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/compose-tunnel-agent/src/http/api-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ const createApiServerHandler = ({ log, currentSshState, machineStatus, envMetada
return
}

if (req.method === 'GET' && path === '/machine-status' && machineStatus) {
if ((req.method === 'GET' || req.method === 'OPTIONS') && path === '/machine-status' && machineStatus) {
const { data, contentType } = await machineStatus()
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,DELETE,PATCH,PUT')
res.setHeader('Access-Control-Allow-Headers', 'Authorization,Content-Type')
res.setHeader('Content-Type', contentType)
res.end(data)
return
Expand Down
14 changes: 14 additions & 0 deletions packages/compose-tunnel-agent/src/http/docker-proxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ export const createDockerProxyHandlers = (
})

const handler = tryHandler({ log }, async (req, res) => {
if (req.method === 'OPTIONS') {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,DELETE,PATCH,PUT')
res.setHeader('Access-Control-Allow-Headers', 'Authorization,Content-Type')
res.statusCode = 200
res.end()
return
}

proxy.on('proxyRes', (_, __, pRes) => {
pRes.setHeader('Access-Control-Allow-Origin', '*')
pRes.setHeader('Access-Control-Allow-Methods', 'GET,POST,DELETE,PATCH,PUT')
pRes.setHeader('Access-Control-Allow-Headers', 'Authorization,Content-Type')
})
proxy.web(req, res)
})

Expand Down
3 changes: 1 addition & 2 deletions tunnel-server/src/proxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ export const proxy = ({
const { activeTunnel, path } = found

req.url = path ?? '/'

if (activeTunnel.access === 'private') {
if (activeTunnel.access === 'private' && req.method !== 'OPTIONS') {
return {
req: await validatePrivateTunnelRequest(req, activeTunnel, session(activeTunnel.publicKeyThumbprint)),
activeTunnel,
Expand Down
Loading