[ST Edge] Issue with HTTP request in Edge drivers

Ok, so, the issue is that when we do this:

driver:register_channel_handler(server.sock, function ()
  server:tick()
end)

The server is running in the same thread as lifecycle_handler.init, so, we need to spawn the server on its own thread as follows:

local cosock = require('cosock')

local server = lux.Server.new_with(cosock.socket.tcp(), { env = 'debug' })

server:listen()

cosock.spawn(function()
  while true do
    server:tick(log.error)
  end
end, "server run loop")

server:get('/', function(req, res)
  res:send('hello world')
end)
--sample of making the request:
local body, code, headers, msg = assert(http.request(string.format("http://...", server:get_ip(), server.port)))

Please, let me know your results

1 Like