【问题标题】:Device Orientation API not working with local webserver设备方向 API 不适用于本地网络服务器
【发布时间】:2020-04-24 21:46:05
【问题描述】:
【问题讨论】:
标签:
javascript
android
html
google-chrome
orientation
【解决方案1】:
我发现您需要通过加密的 HTTPS 连接提供 wep 页面才能访问 Device Orientation API 和一些 mediaDevices。
在开发(而非生产)期间提供 HTTPS 页面的一种简单方法是这个简单的 python 网络服务器:
#!/usr/bin/env python3
# Based on http://www.piware.de/2011/01/creating-an-https-server-in-python/
# generate server.xml with the following command:
# openssl req -new -x509 -keyout key.pem -out server.pem -days 365 -nodes
# run as follows:
# python3 simple-https-server.py
# then in your browser, visit:
# https://localhost:4443
import http.server
import ssl
import os
directory_of_script = os.path.dirname(os.path.abspath(__file__))
#server_address = ('localhost', 4443)
server_address = ('', 4443)
httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket,
server_side=True,
certfile=os.path.join(directory_of_script, "server.pem") ,
keyfile=os.path.join(directory_of_script, "key.pem"),
ssl_version=ssl.PROTOCOL_TLS)
httpd.serve_forever()