构建Facebook Instant Game本地测试环境
💡
原文中文,约700字,阅读约需2分钟。
📝
内容提要
本文介绍了如何构建Facebook Instant Game的本地测试环境,包括安装http-server、生成SSL证书、启动服务器及在浏览器中访问特定URL进行测试,并提供了Safari和Chrome的证书错误解决方案。
🎯
关键要点
- 安装http-server:在游戏本地目录执行命令 $ npm install -g http-server。
- 生成SSL证书:依次执行命令 openssl genrsa 2048 > key.pem 和 openssl req -x509 -days 1000 -new -key key.pem -out cert.pem。
- 启动服务器:使用命令 http-server --ssl -c-1 -p 8080 -a localhost 启动服务器。
- 在浏览器中访问游戏:替换URL中的 YOUR_GAME_ID,访问 https://www.facebook.com/embed/instantgames/YOUR_GAME_ID/player?game_url=https://localhost:8080。
- 解决Safari证书错误:在浏览器中打开 https://localhost:8080,信任证书并输入密码后访问嵌入式URL。
- 解决Chrome证书错误:访问 chrome://flags/#allow-insecure-localhost,选择 Enable,重启浏览器后正常访问。
➡️