Advertisement
DOGGYWOOF

BETA WEBPAGE LOADER

Jul 26th, 2024 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. -- Web Server Code
  2.  
  3. -- Function to handle incoming requests
  4. local function handleRequest()
  5. local modemSide = "top" -- Adjust according to your setup
  6. rednet.open(modemSide)
  7. print("Web Server running...")
  8.  
  9. while true do
  10. local id, message = rednet.receive()
  11.  
  12. if message then
  13. local filePath = "/web.code" .. message:gsub("/", "-") .. ".lua" -- Map URL path to file
  14. if fs.exists(filePath) then
  15. local file = fs.open(filePath, "r")
  16. local code = file.readAll()
  17. file.close()
  18. rednet.send(id, code)
  19. else
  20. rednet.send(id, "Error: Page not found.")
  21. end
  22. end
  23. end
  24. end
  25.  
  26. handleRequest()
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement