Skip to content

Commit

Permalink
fix(runtime): enable cors in runtime; disable cors in gateway ingress (
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow authored Oct 23, 2023
1 parent 04905dc commit 06cafd4
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 32 deletions.
4 changes: 2 additions & 2 deletions runtimes/nodejs/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ export default class Config {
* the serving port, default is 8000
*/
static get PORT(): number {
return (process.env.PORT ?? 8000) as number
return (process.env.__PORT ?? 8000) as number
}

static get STORAGE_PORT(): number {
return (process.env.STORAGE_PORT ?? 9000) as number
return (process.env.__STORAGE_PORT ?? 9000) as number
}

/**
Expand Down
4 changes: 1 addition & 3 deletions runtimes/nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ DatabaseAgent.accessor.ready.then(() => {
DatabaseChangeStream.initialize()
})

if (process.env.NODE_ENV === 'development') {
app.use(cors())
}
app.use(cors())

app.use(express.json({ limit: Config.REQUEST_LIMIT_SIZE }) as any)
app.use(
Expand Down
3 changes: 3 additions & 0 deletions runtimes/nodejs/src/storage-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import './support/cloud-sdk'
import { WebsiteHostingChangeStream } from './support/database-change-stream/website-hosting-change-stream'
import proxy from 'express-http-proxy'
import axios from 'axios'
import cors from 'cors'

const app = express()

app.use(cors())

const tryPath = (bucket: string, path: string) => {
const testPaths = path.endsWith('/')
? [path + 'index.html', '/index.html']
Expand Down
12 changes: 0 additions & 12 deletions server/src/gateway/ingress/bucket-ingress.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,11 @@ export class BucketGatewayService {
'laf.dev/bucket.name': domain.bucketName,
'laf.dev/ingress.type': 'bucket',
// apisix ingress annotations
'k8s.apisix.apache.org/enable-cors': 'true',
'k8s.apisix.apache.org/cors-allow-credential': 'false',
'k8s.apisix.apache.org/cors-allow-headers': '*',
'k8s.apisix.apache.org/cors-allow-methods': '*',
'k8s.apisix.apache.org/cors-allow-origin': '*',
'k8s.apisix.apache.org/cors-expose-headers': '*',
'k8s.apisix.apache.org/svc-namespace': namespace,

// k8s nginx ingress annotations
// websocket is enabled by default in k8s nginx ingress
'nginx.ingress.kubernetes.io/enable-cors': 'true',
'nginx.ingress.kubernetes.io/cors-allow-credentials': 'false',
'nginx.ingress.kubernetes.io/cors-allow-methods': '*',
'nginx.ingress.kubernetes.io/cors-allow-headers':
'DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,x-laf-develop-token,x-laf-func-data,x-amz-content-sha256,x-amz-security-token,x-amz-user-agent,x-amz-date,content-md5',
'nginx.ingress.kubernetes.io/cors-expose-headers': '*',
'nginx.ingress.kubernetes.io/cors-allow-origin': '*',
'nginx.ingress.kubernetes.io/proxy-body-size': '0',
},
},
Expand Down
14 changes: 1 addition & 13 deletions server/src/gateway/ingress/runtime-ingress.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,11 @@ export class RuntimeGatewayService {
'laf.dev/ingress.type': 'runtime',
// apisix ingress annotations
'k8s.apisix.apache.org/enable-websocket': 'true',
'k8s.apisix.apache.org/enable-cors': 'true',
'k8s.apisix.apache.org/cors-allow-credential': 'false',
'k8s.apisix.apache.org/cors-allow-headers': '*',
'k8s.apisix.apache.org/cors-allow-methods': '*',
'k8s.apisix.apache.org/cors-allow-origin': '*',
'k8s.apisix.apache.org/cors-expose-headers': '*',
'k8s.apisix.apache.org/svc-namespace': namespace,

// k8s nginx ingress annotations
// websocket is enabled by default in k8s nginx ingress
'nginx.ingress.kubernetes.io/enable-cors': 'true',
'nginx.ingress.kubernetes.io/cors-allow-credentials': 'false',
'nginx.ingress.kubernetes.io/cors-allow-methods': '*',
'nginx.ingress.kubernetes.io/cors-allow-headers':
'DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,x-laf-develop-token,x-laf-func-data',
'nginx.ingress.kubernetes.io/cors-expose-headers': '*',
'nginx.ingress.kubernetes.io/cors-allow-origin': '*',
'nginx.ingress.kubernetes.io/proxy-body-size': '0',
'nginx.ingress.kubernetes.io/server-snippet':
'client_header_buffer_size 4096k;\nlarge_client_header_buffers 8 512k;\n',
},
Expand Down
2 changes: 0 additions & 2 deletions server/src/gateway/ingress/website-ingress.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ export class WebsiteHostingGatewayService {
'laf.dev/bucket.name': website.bucketName,
'laf.dev/ingress.type': 'website',
// apisix ingress annotations
'k8s.apisix.apache.org/enable-cors': 'true',
'k8s.apisix.apache.org/svc-namespace': namespace,

// k8s nginx ingress annotations
'nginx.ingress.kubernetes.io/enable-cors': 'true',
},
},
spec: { ingressClassName, rules: [rule], tls },
Expand Down

0 comments on commit 06cafd4

Please sign in to comment.