Skip to content

Commit 5e04556

Browse files
[bugfix] IE improvements
1 parent d7033ac commit 5e04556

File tree

10 files changed

+81
-31
lines changed

10 files changed

+81
-31
lines changed

Gruntfile.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,16 @@ module.exports = function (grunt) {
8383
browserify: {
8484
options: {
8585
debug: true,
86-
transform: ['reactify'],
86+
transform: ['reactify', 'uglifyify'],
8787
extensions: ['.jsx']
8888
},
89+
polyfills: {
90+
src: [
91+
'node_modules/es5-shim/es5-shim.js',
92+
'node_modules/es5-shim/es5-sham.js'
93+
],
94+
dest: 'demo/dist/scripts/polyfills.js'
95+
},
8996
app: {
9097
src: [
9198
'src/j-toker.js',
@@ -215,6 +222,7 @@ module.exports = function (grunt) {
215222
'clean',
216223
'sass:dist',
217224
'copy',
225+
'browserify:polyfills',
218226
'browserify:app',
219227
'concat',
220228
'uglify'

demo/app.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ var express = require('express'),
22
request = require('request'),
33
httpProxy = require('http-proxy'),
44
CONFIG = require('config'),
5-
handlebars = require('express-handlebars');
5+
handlebars = require('express-handlebars'),
6+
compress = require('compression');
67

78
var port = process.env.PORT || 7777;
89
var app = express();
@@ -15,7 +16,7 @@ var app = express();
1516
// proxy api requests (for older IE browsers)
1617
app.all('/proxy/*', function(req, res, next) {
1718
// transform request URL into remote URL
18-
var apiUrl = 'http:'+CONFIG.get('apiUrl')+req.params[0];
19+
var apiUrl = 'http:'+CONFIG.get('apiUrl')+'/'+req.params[0];
1920
var r = null;
2021

2122
// preserve GET params
@@ -38,6 +39,12 @@ app.all('/proxy/*', function(req, res, next) {
3839
// redirect to push state url (i.e. /blog -> /#/blog)
3940
app.get(/^(\/[^#\.]+)$/, function(req, res) {
4041
var path = req.url
42+
43+
// preserve GET params
44+
if (req._parsedUrl.search) {
45+
path += req._parsedUrl.search;
46+
}
47+
4148
res.redirect('/#'+path);
4249
});
4350

@@ -57,5 +64,6 @@ app.engine('.html', handlebars({extname: '.html'}));
5764
app.set('views', __dirname + '/' + CONFIG.get('distDir'));
5865
app.set('view engine', '.html');
5966

67+
app.use(compress());
6068
app.use(express.static(__dirname + '/' + CONFIG.get('distDir')));
6169
app.listen(port);

demo/src/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<div id='content'>loading...</div>
99

1010
<script>window.config = {{{config}}};</script>
11+
<script type='text/javascript' src='scripts/polyfills.js'></script>
1112
<script type='text/javascript' src='scripts/main.js'></script>
1213
</body>
1314
</html>

demo/src/scripts/components/access-control.jsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ module.exports = React.createClass({
3333
},
3434

3535
handleSingleRequestClick: function(ev) {
36-
//var url = Auth.getConfig().apiUrl + '/demo/members_only';
37-
var url = Auth.getConfig().apiUrl + $(ev.target).data('url');
36+
var url = Auth.getApiUrl() + $(ev.target).data('url');
3837

3938
$.getJSON(url)
4039
.then(function(resp) {
@@ -52,7 +51,7 @@ module.exports = React.createClass({
5251
},
5352

5453
handleMultiRequestClick: function(ev) {
55-
var url = Auth.getConfig().apiUrl + $(ev.target).data('url');
54+
var url = Auth.getApiUrl() + $(ev.target).data('url');
5655

5756
$.when(
5857
$.getJSON(url),

demo/src/scripts/components/login-form.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ module.exports = React.createClass({
4242
},
4343

4444
handleSignInClick: function(ev) {
45-
console.log('submitting email login', this.state);
4645
Auth.emailSignIn({
4746
email: this.state.email,
4847
password: this.state.password,

demo/src/scripts/main.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Auth.configure([
2020
{
2121
default: {
2222
apiUrl: window.config.apiUrl,
23-
proxyIf: function() { return window.oldIE();}
23+
proxyIf: function() { return window.isOldIE(); }
2424
}
2525
}, {
2626
evilUser: {

dist/jquery.j-toker.js

+26-10
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@
327327
};
328328

329329

330+
Auth.prototype.getApiUrl = function() {
331+
var config = this.getConfig();
332+
return (config.proxyIf()) ? config.proxyUrl : config.apiUrl;
333+
};
334+
335+
330336
// interpolate values of tokenFormat hash with ctx, return new hash
331337
Auth.prototype.buildAuthHeaders = function(ctx) {
332338
var headers = {},
@@ -577,7 +583,7 @@
577583
);
578584
} else {
579585
var config = this.getConfig(opts.config),
580-
url = config.apiUrl + config.tokenValidationPath;
586+
url = this.getApiUrl() + config.tokenValidationPath;
581587

582588
// found saved creds, verify with API
583589
$.ajax({
@@ -634,7 +640,7 @@
634640
}
635641

636642
var config = this.getConfig(opts.config),
637-
url = config.apiUrl + config.emailRegistrationPath,
643+
url = this.getApiUrl() + config.emailRegistrationPath,
638644
dfd = $.Deferred();
639645

640646
opts.config_name = opts.config;
@@ -673,7 +679,7 @@
673679
}
674680

675681
var config = this.getConfig(opts.config),
676-
url = config.apiUrl + config.emailSignInPath,
682+
url = this.getApiUrl() + config.emailSignInPath,
677683
dfd = $.Deferred();
678684

679685
// don't send config name to API
@@ -753,7 +759,7 @@
753759

754760
Auth.prototype.buildOAuthUrl = function(configName, params) {
755761
var config = this.getConfig(configName),
756-
oAuthUrl = config.apiUrl + config.authProviderPaths['github'] +
762+
oAuthUrl = this.getApiUrl() + config.authProviderPaths['github'] +
757763
'?auth_origin_url='+encodeURIComponent(window.location.href) +
758764
'&config_name='+encodeURIComponent(configName || this.getCurrentConfigName());
759765

@@ -804,7 +810,7 @@
804810
}
805811

806812
var config = this.getConfig(opts.config),
807-
signOutUrl = config.apiUrl + config.signOutPath,
813+
signOutUrl = this.getApiUrl() + config.signOutPath,
808814
dfd = $.Deferred();
809815

810816
$.ajax({
@@ -840,7 +846,7 @@
840846
}
841847

842848
var config = this.getConfig(opts.config),
843-
url = config.apiUrl + config.accountUpdatePath,
849+
url = this.getApiUrl() + config.accountUpdatePath,
844850
dfd = $.Deferred();
845851

846852
delete opts.config;
@@ -877,7 +883,7 @@
877883
}
878884

879885
var config = this.getConfig(opts.config),
880-
url = config.apiUrl + config.accountDeletePath,
886+
url = this.getApiUrl() + config.accountDeletePath,
881887
dfd = $.Deferred();
882888

883889
$.ajax({
@@ -918,7 +924,7 @@
918924
}
919925

920926
var config = this.getConfig(opts.config),
921-
url = config.apiUrl + config.passwordResetPath,
927+
url = this.getApiUrl() + config.passwordResetPath,
922928
dfd = $.Deferred();
923929

924930
opts.config_name = opts.config;
@@ -956,7 +962,7 @@
956962
}
957963

958964
var config = this.getConfig(opts.config),
959-
url = config.apiUrl + config.passwordUpdatePath,
965+
url = this.getApiUrl() + config.passwordUpdatePath,
960966
dfd = $.Deferred();
961967

962968
delete opts.config;
@@ -1093,9 +1099,17 @@
10931099
// fetch current auth headers from storage
10941100
var currentHeaders = $.auth.retrieveData(SAVED_CREDS_KEY);
10951101

1102+
console.log('appending request headers');
1103+
10961104
// check config apiUrl matches the current request url
10971105
if (isApiRequest(settings.url) && currentHeaders) {
10981106

1107+
// bust IE cache
1108+
xhr.setRequestHeader(
1109+
'If-Modified-Since',
1110+
'Mon, 26 Jul 1997 05:00:00 GMT'
1111+
);
1112+
10991113
// set header for each key in `tokenFormat` config
11001114
for (var key in $.auth.getConfig().tokenFormat) {
11011115
xhr.setRequestHeader(key, currentHeaders[key]);
@@ -1106,6 +1120,8 @@
11061120

11071121
// update auth credentials after request is made to the API
11081122
Auth.prototype.updateAuthCredentials = function(ev, xhr, settings) {
1123+
console.log('ajax complete', settings);
1124+
11091125
// check config apiUrl matches the current response url
11101126
if (isApiRequest(settings.url)) {
11111127
// set header for each key in `tokenFormat` config
@@ -1222,7 +1238,7 @@
12221238

12231239

12241240
var isApiRequest = function(url) {
1225-
return (url.match($.auth.getConfig().apiUrl));
1241+
return (url.match($.auth.getApiUrl()));
12261242
};
12271243

12281244

0 commit comments

Comments
 (0)