How to send a Access-Control-Allow-Origin: * header
Posted: Fri Jan 02, 2015 7:51 pm
Hi I have a simple script which works fine but I need to send a Access-Control-Allow-Origin: * header to enable CORS so that I can post and get the response via Ajax, am not sure if this can be part of the existing send function or if it needs to be sent prior to that like a pre-header help with this would be appreciated, thanks.
led=0
srv=net.createServer(net.TCP)
srv:listen(8080,function(conn)
conn:on("receive",function(conn,pl)
gpio.mode(3,gpio.OUTPUT)
if string.find(pl,"gpio3=0") then gpio.write(3,0) led=0 end
if string.find(pl,"gpio3=1") then gpio.write(3,1) led=1 end
print(led)
conn:send(led)
conn:on("sent",function(conn) conn:close() end)
end)
end)
led=0
srv=net.createServer(net.TCP)
srv:listen(8080,function(conn)
conn:on("receive",function(conn,pl)
gpio.mode(3,gpio.OUTPUT)
if string.find(pl,"gpio3=0") then gpio.write(3,0) led=0 end
if string.find(pl,"gpio3=1") then gpio.write(3,1) led=1 end
print(led)
conn:send(led)
conn:on("sent",function(conn) conn:close() end)
end)
end)