Open style from url #34

This commit is contained in:
Lukas Martinelli
2017-01-05 19:34:32 +01:00
parent 56aacb0149
commit 7c23fe3646
4 changed files with 42 additions and 20 deletions

24
src/libs/urlopen.js Normal file
View File

@@ -0,0 +1,24 @@
import request from 'request'
import url from 'url'
import style from './style.js'
export function initialStyleUrl() {
const initialUrl = url.parse(window.location.href, true)
console.log(initialUrl)
return (initialUrl.query || {}).style
}
export function loadStyleUrl(styleUrl, cb) {
console.log('Loading style', styleUrl)
request({
url: styleUrl,
withCredentials: false,
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
cb(style.ensureStyleValidity(JSON.parse(body)))
} else {
console.warn('Could not fetch default style', styleUrl)
cb(style.emptyStyle)
}
})
}