|
楼主 |
发表于 2020-7-3 22:38:35
|
显示全部楼层
河小马 发表于 2020-7-3 21:23
& y$ Z+ b1 @* @% z! hshopify 可以前面挂cf吗?
# n/ o& c& \+ W+ c. _1 K
) o, I6 \: o8 G) ]$ B$ ?- R5 Acf 实现这个很容易 4 z' G; V. T1 Y9 F! y+ `# I9 z) [; ?
应该不行,只能用DNS Only模式,然后shopify会generate一个let's encrypt,我看几个top shopify店铺都是这样的
9 {9 K/ V, ?' x- P; m/ }8 C
* O- X$ a5 s" n4 N7 C自己写code感觉就很麻烦了。。。6 c4 Y# G: v9 \/ F- I+ J9 ~# d
5 a$ I8 y, V% |8 j在shopify的社区找到了这个代码,不过这个freegeoip.app感觉不稳3 H: I( g1 M2 I2 t, L4 `% h5 ~
9 J) O* a# ]8 g8 j' _% A/ ^- // IpGeolocation/ J. n/ j! v7 i! z& B$ F
- var httpRequest = new XMLHttpRequest();" T0 w# ^& V7 g2 i; |/ M* P
) a3 {& o: R+ b; z& \- httpRequest.onreadystatechange = function() {2 n$ D! C" }* E ~2 B7 x N
- if (4 === this.readyState && 200 === this.status) {: ?5 n7 x, D( f: g# V @
- var json = JSON.parse(this.responseText);! A# [7 k; [; y& ?' i
- redirect(json.country_code);$ j0 ^6 L& e# Q8 I# N0 S
- }
2 |3 c' @# v# |% Q5 `9 y8 F - }
4 ^. `; H& s/ Q9 Z5 P# @/ ? - httpRequest.open("GET", "https://freegeoip.app/json/", false);
( `) G9 g. C f - httpRequest.setRequestHeader("Accept", "application/json");
; e, g5 I* c4 R E! N8 \ - httpRequest.send();
. O- @( J# k9 K6 Q/ p! K* U
) @( q/ D7 ?; `4 l" j- function redirect(country_code) {
8 g/ e! N% m" H2 u - 8 J& x$ @* |# d' Y0 Z
- if (country_code == "CN" ) {
2 N* T0 R% |; q; y$ r - Q- ]3 X h" n$ q1 k# l# H
- window.location.href = "https://www.nasa.gov/";
0 ]5 b( I: }8 W5 l3 m. ?7 K' h - }
1 O0 u1 H' {1 g5 i) ~& \: f3 \3 Y
5 u8 f9 L& g' H8 D- k7 c- else if) P- T' S2 X; T* z' d
- (country_code == "MO" ) {4 o! y' |/ }" G3 n8 \
- window.location.href = "https://www.nasa.gov/";9 e# f" A! ]3 H9 [3 v- H
- }
- v' O4 V, r n' k9 o L/ o; F' c - % z( h6 m$ j( O6 V
- " j- }& L- N: w) _: E
- else if
6 F4 S" r0 \, v4 @. w W. h+ ^ - (country_code == "SG" ) {
6 \, n: O/ V$ U+ q" ]* K
% a( p9 z! |0 \) l* i+ u- window.location.href = "https://www.nasa.gov/";
) `: ^8 F I! `1 i - }
! w' I8 h+ a; G
" R* P2 K8 v3 j2 v- else if
: Q9 V3 B9 i8 G! P; X5 }- O4 M - (country_code == "EE" ) {
) Y8 M. P2 ~5 ~9 j' H. T( M: M - $ A) q# K+ P7 n2 a$ Y. R
- window.location.href = "https://www.nasa.gov/";% H! J% z3 Y! m- [. m( H6 D
- }
5 K4 `" J8 a0 H& P
3 o# z8 T: L0 c2 j. }/ H" w- 8 a) H5 ?0 L. [, U/ u, s
- else {, h0 s5 _5 \5 y( \' U
- return
. ^" u0 [+ X/ E$ O5 J - }+ D: [7 X. F/ s
- }
复制代码 |
|