misc.rst 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 其他
  2. ============
  3. .. _codemirror_options:
  4. 常用的Codemirror选项
  5. --------------------
  6. * ``mode`` (str): 代码语言。支持的语言有:https://codemirror.net/mode/index.html
  7. * ``theme`` (str): 编辑器主题。可使用的主题:https://codemirror.net/demo/theme.html
  8. * ``lineNumbers`` (bool): 是否显示行号
  9. * ``indentUnit`` (int): 缩进使用的空格数
  10. * ``tabSize`` (int): 制表符宽度
  11. * ``lineWrapping`` (bool): 是否换行以显示长行
  12. .. _nginx_ws_config:
  13. Nginx WebSocket配置示例
  14. -----------------------
  15. 假设后端服务器运行在 ``localhost:5000`` 地址,并将PyWebIO的后端接口绑定到 ``/tool/io`` 路径上,则通过Nginx访问PyWebIO服务的配置如下::
  16. map $http_upgrade $connection_upgrade {
  17. default upgrade;
  18. '' close;
  19. }
  20. server {
  21. listen 80;
  22. location /tool/ {
  23. alias /path/to/pywebio/static/dir/;
  24. }
  25. location /tool/io {
  26. proxy_read_timeout 300s;
  27. proxy_send_timeout 300s;
  28. proxy_http_version 1.1;
  29. proxy_set_header Upgrade $http_upgrade;
  30. proxy_set_header Connection $connection_upgrade;
  31. proxy_pass http://localhost:5000;
  32. }
  33. }
  34. 以上配置文件将PyWebIO的静态文件托管到 ``/tool/`` 目录下, 并将 ``/tool/io`` 反向代理到 ``localhost:5000``
  35. .. note::
  36. 使用以上配置文件后,您还需要在 ``webio_handler`` 或 ``start_server`` 函数中将nginx绑定的域名添加到 ``allowed_origins`` 参数指定的列表中
  37. PyWebIO的静态文件的路径可使用命令 ``python3 -c "import pywebio; print(pywebio.STATIC_PATH)"`` 获得,你也可以将静态文件复制到其他目录下::
  38. cp -r `python3 -c "import pywebio; print(pywebio.STATIC_PATH)"` ~/web