|
楼主 |
发表于 2020-7-3 22:38:35
|
显示全部楼层
河小马 发表于 2020-7-3 21:23: j9 y% a1 Z( K( N) b6 H4 T" H
shopify 可以前面挂cf吗?
; v/ `; \- v, M' s6 o; B8 D% a# x) ?0 }6 y, k
cf 实现这个很容易 ( s/ R6 p$ J9 F7 v, M
应该不行,只能用DNS Only模式,然后shopify会generate一个let's encrypt,我看几个top shopify店铺都是这样的3 ]3 G; ^! L, s) M
: H1 e6 `6 J# [8 G
自己写code感觉就很麻烦了。。。
3 i' p/ C8 |1 f& s! v/ S/ a {
$ N. E8 y& z# `5 l4 L在shopify的社区找到了这个代码,不过这个freegeoip.app感觉不稳
8 L* Y+ `# x7 m: f5 u2 m' U9 q; J5 u# D3 p+ z" Q' Y- D
- // IpGeolocation
n, i* j$ T' X, A* R4 o" a" A - var httpRequest = new XMLHttpRequest();
/ J! _, C# m7 a- r! f9 a1 ]% _' F - ' w4 i) C% d* p/ |- r" Q! a
- httpRequest.onreadystatechange = function() {
p( N. k6 q3 H: P7 a7 a( g - if (4 === this.readyState && 200 === this.status) {& l$ m1 k& T! n0 \
- var json = JSON.parse(this.responseText);
8 K5 F: Z) E1 A) |6 b- q - redirect(json.country_code); h3 S1 z6 c8 ?" y! s
- }
- }/ `4 ]7 D1 ~6 \7 b R0 V" T+ a9 c - }7 O- W% o& H3 Y: s% D$ [
- httpRequest.open("GET", "https://freegeoip.app/json/", false);5 R9 |6 d) F8 R$ `& X* R+ P
- httpRequest.setRequestHeader("Accept", "application/json");
) ^$ `8 b( A, m% [' G3 J - httpRequest.send();
5 ?+ B5 }5 [6 x; p$ K; ?
$ M& @7 L L- c$ J8 ~3 w* m6 g% b4 T- function redirect(country_code) {
$ n/ C; c1 f( U% j# o" e. _ - $ B2 l5 f" m3 q/ \" K
- if (country_code == "CN" ) {
/ Q" T# e2 a0 G1 x
7 b0 J- F8 j" [3 s5 }- window.location.href = "https://www.nasa.gov/";
# W- I" f) Q/ f: z - }
0 O5 U+ ?/ m. H/ Q& o5 J5 a. _: \
9 F6 I" F& b' }7 J+ l0 K- else if
, V- T/ b( H; `' K - (country_code == "MO" ) {
E' d5 G3 \* m. A3 Y2 L5 \, ~' x2 d - window.location.href = "https://www.nasa.gov/";
4 A& V# F: ]8 q* i. C - }) }2 S5 k- u. ^5 |
- / [! G0 K1 y; C. \7 v! `- U) Y. o
- , q0 h7 r2 z& k1 B. ?
- else if
3 D4 M8 L5 R, [8 h W0 c - (country_code == "SG" ) {" W9 B, s4 |# B2 g$ ~7 m
- ) r5 n/ W/ r( q; Z& g
- window.location.href = "https://www.nasa.gov/";
, T6 Z! `& {: t1 h3 A& Y - } j2 T2 x# M8 s. v4 E$ x$ Z
- 1 [, ]$ g& P4 V; W1 c! ?' k: B
- else if* C! U8 M$ `/ c6 A3 j" M3 z
- (country_code == "EE" ) {, r6 R: [/ d3 K1 y
- % F0 y" j7 a+ J7 s7 c! y0 u; p9 z. p
- window.location.href = "https://www.nasa.gov/";6 l* X$ z: f* d7 h- m& V' w: j/ l
- }
8 f& |0 Q5 p6 d5 L
, t' U! Y0 {% D' P0 z: O6 |) ?- ) _6 J& _5 z2 p% h! }, }( k
- else {( x# Q: E/ ~, D- W! G
- return
: p% w$ Z& ^; M9 ] - }( w% }; w/ z* B6 S
- }
复制代码 |
|