A server-side web framework written in Forth. http://www.1-9-9-1.com
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

51 líneas
1.1KB

  1. \ 1991
  2. include unix/socket.fs
  3. \ User-defined routing
  4. wordlist constant routes
  5. : find-route ( addr u -- data )
  6. routes search-wordlist if
  7. >body @
  8. else 0 then ;
  9. : register-route ( data addr u -- )
  10. 2dup routes search-wordlist if
  11. routes drop nip nip
  12. >body !
  13. else
  14. routes get-current >r set-current \ switch definition word lists
  15. nextname create ,
  16. r> set-current
  17. then ;
  18. \ Internal request handling
  19. : read-request ( socket -- addr u ) pad 4096 read-socket ;
  20. : send-response ( addr u socket -- )
  21. dup >R write-socket R> close-socket ;
  22. : start-server { server client }
  23. begin
  24. server 255 listen
  25. server accept-socket to client
  26. client read-request type s\" HTTP/1.1 200 OK\n Content-Type: text/html\n\n fffff" client send-response
  27. again ;
  28. \ Userland
  29. : 1991: ( port -- )
  30. create-server 0 start-server ;
  31. : 1991/ ( "<path> <word>" -- )
  32. bl word ' swap count register-route ;
  33. \ App demo:
  34. : handle-hi ." hi!" ; \ not sure printing is the way to go?
  35. 1991/ hi handle-hi
  36. \ 8080 1991: