Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jxxcarlson/2af50265f66d822eb933d323140be5ec to your computer and use it in GitHub Desktop.
Save jxxcarlson/2af50265f66d822eb933d323140be5ec to your computer and use it in GitHub Desktop.
Deno - CORS problem with this function
export const addDocument = async ({
request,
response,
}: {
request: any
response: any
}) => {
response.headers.set('Access-Control-Allow-Origin', '*')
console.log("processing POST request")
const {
value : {token, fileName, id, content}
} = await request.body()
if (token == "abracadabra") {
const doc_ = {id: id, fileName: fileName, content: content}
if (isNotPresent(doc_, documents)) {
documents.push(doc_)
console.log("pushing document: " + doc_.fileName)
response.body = { msg: 'OK' }
response.status = 200
} else {
console.log("duplicate document")
response.body = { msg: 'file already exists' }
response.status = 200
}
} else {
response.body = { msg: 'Token does not match' }
response.status = 400
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment