Added response header checking
This commit is contained in:
parent
a0a7f35a6f
commit
efff34774e
|
@ -88,6 +88,7 @@ A javascript library providing server defined loading of assets for a single pag
|
||||||
* server.timeout = The timeout to download the server resources. (default: 4096)
|
* server.timeout = The timeout to download the server resources. (default: 4096)
|
||||||
* server.flag = The window flag which is set when the server.url is know. (default: 'FFServerUrl')
|
* server.flag = The window flag which is set when the server.url is know. (default: 'FFServerUrl')
|
||||||
* server.header.request = An key value object with the request headers. (default: {'X-FFSpaLoader': 'sync'})
|
* server.header.request = An key value object with the request headers. (default: {'X-FFSpaLoader': 'sync'})
|
||||||
|
* server.header.response = An key value object with the required response headers. (default: {})
|
||||||
* question.transport = The transport to prefix the server.url with. (default: 'http://')
|
* question.transport = The transport to prefix the server.url with. (default: 'http://')
|
||||||
* question.title = The question ui title. (default: 'Server')
|
* question.title = The question ui title. (default: 'Server')
|
||||||
* question.submit = The start button text. (default: 'Start')
|
* question.submit = The start button text. (default: 'Start')
|
||||||
|
@ -198,7 +199,6 @@ A javascript library providing server defined loading of assets for a single pag
|
||||||
## Todo
|
## Todo
|
||||||
|
|
||||||
* test in production
|
* test in production
|
||||||
* Server header check support
|
|
||||||
* Add instance websql options so it can also be used in application code.
|
* Add instance websql options so it can also be used in application code.
|
||||||
* Split assets per type so do js first then boot then css + cssData.
|
* Split assets per type so do js first then boot then css + cssData.
|
||||||
* Add more tests
|
* Add more tests
|
||||||
|
@ -215,10 +215,11 @@ Add unit tests for any new or changed functionality. Lint and test your code.
|
||||||
## Release History
|
## Release History
|
||||||
|
|
||||||
### 0.2.0
|
### 0.2.0
|
||||||
* Dropped error.style and question.style for css file.
|
* Moved error.style and question.style to css file.
|
||||||
* Change dist with extra css/js folder.
|
* Change dist with extra css/js folder.
|
||||||
* Added loader progress bar.
|
* Added loader progress bar.
|
||||||
* refined css so question/loader/error are equal.
|
* refined css so question/loader/error are equal.
|
||||||
|
* Added response header check support.
|
||||||
|
|
||||||
### 0.1.1
|
### 0.1.1
|
||||||
* Moved websql delete timeout to cleanServerlUrl for faster boot.
|
* Moved websql delete timeout to cleanServerlUrl for faster boot.
|
||||||
|
|
|
@ -74,7 +74,7 @@
|
||||||
request: {
|
request: {
|
||||||
'X-FFSpaLoader': 'sync'
|
'X-FFSpaLoader': 'sync'
|
||||||
},
|
},
|
||||||
response: { // TODO: add header check support
|
response: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -336,6 +336,23 @@
|
||||||
httpRequest.onreadystatechange = function() {
|
httpRequest.onreadystatechange = function() {
|
||||||
if (httpRequest.readyState === 4 && httpRequest.status === 200) {
|
if (httpRequest.readyState === 4 && httpRequest.status === 200) {
|
||||||
utilDebug('utilHttpFetch url \"'+url+'\" done in '+(new Date().getTime()-startTime)+' ms.');
|
utilDebug('utilHttpFetch url \"'+url+'\" done in '+(new Date().getTime()-startTime)+' ms.');
|
||||||
|
|
||||||
|
var headerResponseKeys = Object.keys(options.server.header.response);
|
||||||
|
for (var headerResponseKeyIdx in headerResponseKeys) {
|
||||||
|
var headerResponseKey = headerResponseKeys[headerResponseKeyIdx];
|
||||||
|
var headerResponseValue = options.server.header.response[headerResponseKey];
|
||||||
|
var value = httpRequest.getResponseHeader(headerResponseKey);
|
||||||
|
if (value === null) {
|
||||||
|
return cb('Header missing: '+headerResponseKey);
|
||||||
|
}
|
||||||
|
if (headerResponseValue === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (headerResponseValue !== value) {
|
||||||
|
return cb('Header mismatch: '+headerResponseKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cb(null, httpRequest);
|
cb(null, httpRequest);
|
||||||
} else if (httpRequest.readyState === 4) {
|
} else if (httpRequest.readyState === 4) {
|
||||||
cb('Wrong status '+httpRequest.status);
|
cb('Wrong status '+httpRequest.status);
|
||||||
|
@ -602,7 +619,7 @@
|
||||||
var stepProgres10 = 0;
|
var stepProgres10 = 0;
|
||||||
|
|
||||||
var createUITimeout = setTimeout( function () {
|
var createUITimeout = setTimeout( function () {
|
||||||
utilDebug('createLoaderBar');
|
utilDebug('createLoaderBar after timeout: '+options.loader.await);
|
||||||
|
|
||||||
rootTag = document.createElement('div');
|
rootTag = document.createElement('div');
|
||||||
rootTag.setAttribute('class','ffWrapper');
|
rootTag.setAttribute('class','ffWrapper');
|
||||||
|
@ -746,10 +763,8 @@
|
||||||
|
|
||||||
var progressBar = createLoaderBar(resources);
|
var progressBar = createLoaderBar(resources);
|
||||||
var loadResourceStep = function (resource, cb) {
|
var loadResourceStep = function (resource, cb) {
|
||||||
//setTimeout(function() {
|
|
||||||
loadResource(resource,cb);
|
loadResource(resource,cb);
|
||||||
progressBar.nextResource(resource);
|
progressBar.nextResource(resource);
|
||||||
//}, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cacheHasService('meta')) {
|
if (cacheHasService('meta')) {
|
||||||
|
@ -819,10 +834,9 @@
|
||||||
var resourcesUrl = options.server.url + options.server.assets;
|
var resourcesUrl = options.server.url + options.server.assets;
|
||||||
utilDebug('askUrlStart check assets '+resourcesUrl);
|
utilDebug('askUrlStart check assets '+resourcesUrl);
|
||||||
|
|
||||||
// TODO: check headers
|
|
||||||
utilHttpFetch(resourcesUrl,function(err, httpRequest) {
|
utilHttpFetch(resourcesUrl,function(err, httpRequest) {
|
||||||
if (err !== null) {
|
if (err !== null) {
|
||||||
inputErrorTag.appendChild(document.createTextNode('Error could not get data.'));
|
inputErrorTag.appendChild(document.createTextNode('Error '+err));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (httpRequest.responseText.length === 0) {
|
if (httpRequest.responseText.length === 0) {
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
FFSpaLoader.options.debug.enable = true;
|
FFSpaLoader.options.debug.enable = true;
|
||||||
FFSpaLoader.options.boot.angular.modules.push('exampleUI');
|
FFSpaLoader.options.boot.angular.modules.push('exampleUI');
|
||||||
FFSpaLoader.options.server.assets = '/static/spa-client-resources';
|
FFSpaLoader.options.server.assets = '/static/spa-client-resources';
|
||||||
|
FFSpaLoader.options.server.header.response['X-My-Api'] = 'noknok';
|
||||||
FFSpaLoader.start();
|
FFSpaLoader.start();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -104,6 +104,7 @@ server.use(morgan('dev'));
|
||||||
server.use(cors({credentials: true, origin: '*'}));
|
server.use(cors({credentials: true, origin: '*'}));
|
||||||
server.set('view engine', 'ejs');
|
server.set('view engine', 'ejs');
|
||||||
server.set('views', path.join(__dirname,'www_views'));
|
server.set('views', path.join(__dirname,'www_views'));
|
||||||
|
server.use(function(req, res, next) { res.header('X-My-Api', 'noknok');next(); });
|
||||||
server.use('/static', express.static(path.join(__dirname,'www_static')));
|
server.use('/static', express.static(path.join(__dirname,'www_static')));
|
||||||
server.use('/static/module/bootstrap', express.static(path.join(__dirname,'../node_modules/bootstrap/dist')));
|
server.use('/static/module/bootstrap', express.static(path.join(__dirname,'../node_modules/bootstrap/dist')));
|
||||||
server.use('/static/module/jquery', express.static(path.join(__dirname,'../node_modules/jquery/dist')));
|
server.use('/static/module/jquery', express.static(path.join(__dirname,'../node_modules/jquery/dist')));
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
FFSpaLoader.options.debug.enable = true;
|
FFSpaLoader.options.debug.enable = true;
|
||||||
FFSpaLoader.options.boot.angular.modules.push('exampleUI');
|
FFSpaLoader.options.boot.angular.modules.push('exampleUI');
|
||||||
FFSpaLoader.options.server.assets = '/static/spa-client-resources';
|
FFSpaLoader.options.server.assets = '/static/spa-client-resources';
|
||||||
|
FFSpaLoader.options.server.header.response['X-My-Api'] = 'noknok';
|
||||||
FFSpaLoader.start();
|
FFSpaLoader.start();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue