2
0
Fork 0

Added response header checking

This commit is contained in:
Willem 2016-02-27 00:24:43 +01:00
parent a0a7f35a6f
commit efff34774e
5 changed files with 26 additions and 8 deletions

View file

@ -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.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.response = An key value object with the required response headers. (default: {})
* question.transport = The transport to prefix the server.url with. (default: 'http://')
* question.title = The question ui title. (default: 'Server')
* 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
* test in production
* Server header check support
* 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.
* Add more tests
@ -215,10 +215,11 @@ Add unit tests for any new or changed functionality. Lint and test your code.
## Release History
### 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.
* Added loader progress bar.
* refined css so question/loader/error are equal.
* Added response header check support.
### 0.1.1
* Moved websql delete timeout to cleanServerlUrl for faster boot.

View file

@ -74,7 +74,7 @@
request: {
'X-FFSpaLoader': 'sync'
},
response: { // TODO: add header check support
response: {
}
}
},
@ -336,6 +336,23 @@
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === 4 && httpRequest.status === 200) {
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);
} else if (httpRequest.readyState === 4) {
cb('Wrong status '+httpRequest.status);
@ -602,7 +619,7 @@
var stepProgres10 = 0;
var createUITimeout = setTimeout( function () {
utilDebug('createLoaderBar');
utilDebug('createLoaderBar after timeout: '+options.loader.await);
rootTag = document.createElement('div');
rootTag.setAttribute('class','ffWrapper');
@ -746,10 +763,8 @@
var progressBar = createLoaderBar(resources);
var loadResourceStep = function (resource, cb) {
//setTimeout(function() {
loadResource(resource,cb);
progressBar.nextResource(resource);
//}, 1000);
}
if (cacheHasService('meta')) {
@ -819,10 +834,9 @@
var resourcesUrl = options.server.url + options.server.assets;
utilDebug('askUrlStart check assets '+resourcesUrl);
// TODO: check headers
utilHttpFetch(resourcesUrl,function(err, httpRequest) {
if (err !== null) {
inputErrorTag.appendChild(document.createTextNode('Error could not get data.'));
inputErrorTag.appendChild(document.createTextNode('Error '+err));
return;
}
if (httpRequest.responseText.length === 0) {

View file

@ -15,6 +15,7 @@
FFSpaLoader.options.debug.enable = true;
FFSpaLoader.options.boot.angular.modules.push('exampleUI');
FFSpaLoader.options.server.assets = '/static/spa-client-resources';
FFSpaLoader.options.server.header.response['X-My-Api'] = 'noknok';
FFSpaLoader.start();
</script>
</body>

View file

@ -104,6 +104,7 @@ server.use(morgan('dev'));
server.use(cors({credentials: true, origin: '*'}));
server.set('view engine', 'ejs');
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/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')));

View file

@ -11,6 +11,7 @@
FFSpaLoader.options.debug.enable = true;
FFSpaLoader.options.boot.angular.modules.push('exampleUI');
FFSpaLoader.options.server.assets = '/static/spa-client-resources';
FFSpaLoader.options.server.header.response['X-My-Api'] = 'noknok';
FFSpaLoader.start();
</script>
</body>