Warning:正如您對問題的評論所述,建議您在生產和開發之間拆分代碼/配置。但如果你真的想這樣做,得到的答案是,因爲它遵循:
You'll most likely need to use a service to check you public ip
如果你正在使用jQuery你可以做這樣的事情:
$.get('//freegeoip.net/json/', function(data) {
if (data.ip === '<Your IP>') {
// Your specific code goes here
}
});
對於香草JavaScript的答案:
fetch('//freegeoip.net/json/').then(function(response) {
return response.json()
}).then(function(data) {
if (data.ip === '<Your IP>') {
// Your specific code goes here
}
});
注意:謹防API的速率限制,他們顯示在標題,你可能需要實現自己的API,如果你得到太多流量。
設置一個cookie並檢查它的存在。或者一個localStorage密鑰。 – zerkms
任何原因,你不能有一個單獨的開發和生產線ENV – Koborl
@Koborl http://i.imgur.com/y7Hm9.jpg – zerkms