@@ -19,6 +19,7 @@ const bool = (input) => {
1919const route = async ( req , res ) => {
2020 const { pathname, query } = url . parse ( req . url , true ) ;
2121 const {
22+ os,
2223 browser,
2324 script,
2425 redirect = true ,
@@ -79,24 +80,26 @@ const route = async (req, res) => {
7980 if ( pathname === "/script.js" && script ) {
8081 res . writeHead ( 200 , { "Content-Type" : "text/javascript" } ) ;
8182 body = readFileSync ( `./dist${ script } ` , "utf8" ) ;
82- if ( CI ) {
83- body = body . replace ( / " h t t p s : \/ \/ q u e u e \. " / g, '"http://"' ) ;
84- body = body . replace (
85- / " s i m p l e a n a l y t i c s c d n \. c o m " / g,
86- `"localhost:${ SERVER_PORT } "`
87- ) ;
88- } else {
89- body = body . replace ( / " h t t p s : / gi, `"http:` ) ;
90- body = body . replace ( / " s i m p l e a n a l y t i c s c d n .c o m " / gi, `"localhost"` ) ;
91- }
83+
84+ const localhost =
85+ os === "ios" || browser === "safari"
86+ ? `bs-local.com:${ SERVER_PORT } `
87+ : `localhost:${ SERVER_PORT } ` ;
88+
89+ body = body . replace ( / " h t t p s : \/ \/ q u e u e \. " / g, '"http://"' ) ;
90+ body = body . replace ( / " s i m p l e a n a l y t i c s c d n \. c o m " / g, `"${ localhost } "` ) ;
91+
9292 res . write ( body ) ;
9393 return res . end ( ) ;
9494 }
9595
9696 res . writeHead ( 200 , { "Content-Type" : "text/html" } ) ;
9797 body = `<!DOCTYPE html>
9898 <html>
99- <head><title>Simple Analytics Test</title></head>
99+ <head>
100+ <title>Simple Analytics Test</title>
101+ <meta name="viewport" content="width=device-width, initial-scale=1">
102+ </head>
100103 <body style="height: 300vh;">
101104 <h1>Path: ${ pathname } </h1>` ;
102105
@@ -125,18 +128,22 @@ const route = async (req, res) => {
125128 }
126129
127130 if ( script ) {
128- const params = script ? new URLSearchParams ( { script } ) . toString ( ) : "" ;
131+ const params = new URLSearchParams ( { script, browser , os } ) . toString ( ) ;
129132 const attributes = [ "defer" , "async" ] ;
130133 if ( allowparams ) attributes . push ( `data-allow-params="${ allowparams } "` ) ;
131134 const attr = attributes . join ( " " ) ;
132135 const host =
133- browser === "ie "
134- ? `http://localhost :${ SERVER_PORT } `
136+ os === "ios" || browser === "safari "
137+ ? `http://bs-local.com :${ SERVER_PORT } `
135138 : `http://localhost:${ SERVER_PORT } ` ;
136139 const scriptHTML = `<script ${ attr } src="${ host } /script.js?${ params } "></script>` ;
137140 body += scriptHTML ;
141+ body += `<p><code><script ${ attr } src="${ host } /script.js?${ params } "></script></code></p>` ;
138142 }
139143
144+ body += `<p>OS: ${ os } </p>` ;
145+ body += `<p>Browser: ${ browser } </p>` ;
146+
140147 body += `</body></html>` ;
141148
142149 res . write ( body ) ;
0 commit comments