scripting: add globals.ip variable
This commit is contained in:
parent
984882e9f6
commit
cf56e27c87
4 changed files with 7 additions and 1 deletions
|
|
@ -72,8 +72,9 @@ This syntax allows writing formulas in pure javascript. The code will be compile
|
|||
- `console`: javascript console
|
||||
- `locals`: object for storing/reading arbitrary values. Changing its properties *does not* trigger any synchronisation even if the value is used somewhere else.
|
||||
- `globals`: same as `locals` but shared between all widgets, contains a few useful variables:
|
||||
- `screen`: `{width, height}`
|
||||
- `screen`: client screen dimensions (`{width, height}`)
|
||||
- `env`: client options (ie: url query options),
|
||||
- `ip`: client's ip address,
|
||||
- `url`: server url,
|
||||
- `platform`: operating system as seen by the client
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
window.IP = window.IP || ''
|
||||
window.ENV = window.ENV || {}
|
||||
location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, (s,k,v)=>{
|
||||
ENV[k]=v
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ class Vm {
|
|||
globals = {
|
||||
screen: {width: screen.width, height: screen.height},
|
||||
env: deepCopy(ENV),
|
||||
ip: IP,
|
||||
url: document.location.host,
|
||||
platform: navigator.platform
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,9 +51,12 @@ function httpRoute(req, res) {
|
|||
|
||||
if (url === '/' || url.indexOf('/?') === 0) {
|
||||
|
||||
var ip = req.connection.remoteAddress.replace('::ffff:', '')
|
||||
|
||||
fs.createReadStream(path.resolve(__dirname + '/../client/index.html'))
|
||||
.pipe(replaceStream('</body>', `
|
||||
<script>
|
||||
window.IP=${JSON.stringify(ip)}
|
||||
window.ENV=${JSON.stringify(clientOptions)}
|
||||
window.READ_ONLY=${JSON.stringify(settings.read('read-only'))}
|
||||
</script></body>`))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue