2
0

luci 660 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env ucode
  2. 'use strict';
  3. import { stdin, stdout } from 'fs';
  4. import dispatch from 'luci.dispatcher';
  5. import request from 'luci.http';
  6. const input_bufsize = 4096;
  7. let input_available = +getenv('CONTENT_LENGTH') || 0;
  8. function read(len) {
  9. if (input_available == 0) {
  10. stdin.close();
  11. return null;
  12. }
  13. let chunk = stdin.read(min(input_available, len ?? input_bufsize, input_bufsize));
  14. if (chunk == null) {
  15. input_available = 0;
  16. stdin.close();
  17. }
  18. else {
  19. input_available -= length(chunk);
  20. }
  21. return chunk;
  22. }
  23. function write(data) {
  24. return stdout.write(data);
  25. }
  26. let req = request(getenv(), read, write);
  27. dispatch(req);
  28. req.close();