Skip to content

Commit

Permalink
Merge pull request #115 from konnected-io/cloud-provisioning
Browse files Browse the repository at this point in the history
fixes preflight response for iOS CORS check
  • Loading branch information
heythisisnate authored Dec 17, 2019
2 parents c32f0d4 + 64735ca commit b8c930a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 4 deletions.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/lfs/device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local me = {
id = "uuid:8f655392-a778-4fee-97b9-4825918" .. string.format("%x", node.chipid()),
name = "Konnected",
hwVersion = "2.3.0",
swVersion = "2.3.2",
swVersion = "2.3.3",
http_port = math.floor(node.chipid()/1000) + 8000,
urn = "urn:schemas-konnected-io:device:Security:1"
}
Expand Down
9 changes: 7 additions & 2 deletions src/lfs/httpd_res.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ local function respondWithText(sck, body, ty, st, headers)
local ty = ty or "application/json"
local st = st or 200
local headers = headers or ''
local contentLength = string.len(body)

if contentLength > 0 then
headers = table.concat({ headers, 'Content-Type: ', ty, '\r\nContent-Length: ', contentLength, '\r\n' })
end

local sendContent = table.concat({
'HTTP/1.1 ', st, '\r\nContent-Type: ', ty, '\r\nContent-Length: ', string.len(body),
'\r\nAccess-Control-Allow-Origin: *\r\n', headers, '\r\n', body
'HTTP/1.1 ', st, '\r\nAccess-Control-Allow-Origin: *\r\n', headers, '\r\n', body
})
local function doSend(s)
if sendContent == '' then
Expand Down
Binary file added src/lfs/lfs-2.3.2.img
Binary file not shown.
3 changes: 2 additions & 1 deletion src/lfs/server_receiver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ local function httpReceiver(sck, payload)
local response = require("httpd_res")()

if request.method == 'OPTIONS' then
response.text(sck, "", nil, 204, table.concat({
print("Heap: ", node.heap(), "HTTP: ", "Options")
response.text(sck, "", nil, nil, table.concat({
"Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS\r\n",
"Access-Control-Allow-Headers: Content-Type\r\n"
}))
Expand Down

0 comments on commit b8c930a

Please sign in to comment.