d7002057d7
This PR moves the tldraw.com app into the public repo. ### Change Type - [x] `internal` — Any other changes that don't affect the published package[^2] --------- Co-authored-by: Dan Groshev <git@dgroshev.com> Co-authored-by: alex <alex@dytry.ch>
35 lines
845 B
TypeScript
35 lines
845 B
TypeScript
import Cors from 'cors'
|
|
|
|
const whitelist = [
|
|
'http://localhost:3000',
|
|
'http://localhost:4000',
|
|
'http://localhost:5420',
|
|
'https://www.tldraw.com',
|
|
'https://staging.tldraw.com',
|
|
process.env.NEXT_PUBLIC_VERCEL_URL,
|
|
'vercel.app',
|
|
]
|
|
|
|
export const cors = Cors({
|
|
methods: ['POST'],
|
|
origin: function (origin, callback) {
|
|
if (origin?.endsWith('.tldraw.com')) {
|
|
callback(null, true)
|
|
} else if (origin?.endsWith('-tldraw.vercel.app')) {
|
|
callback(null, true)
|
|
} else if (origin && whitelist.includes(origin)) {
|
|
callback(null, true)
|
|
} else {
|
|
callback(new Error(`Not allowed by CORS (${origin})`))
|
|
}
|
|
},
|
|
})
|
|
|
|
export function runCorsMiddleware(req: any, res: any) {
|
|
return new Promise((resolve, reject) => {
|
|
cors(req, res, (result) => {
|
|
if (result instanceof Error) return reject(result)
|
|
return resolve(result)
|
|
})
|
|
})
|
|
}
|