Skip to content

Commit 667715e

Browse files
committed
Closes #182.
1 parent d2a1555 commit 667715e

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- #170 - Global callbacks
1111
- #171 - "not in" query
1212
- #177 - Allow promises to be returned in lifecycle hooks
13+
- #182 - option to force trailing slash (DSHttpAdapterProvider.defaults.forceTrailingSlash)
1314

1415
###### Backwards compatible bug fixes
1516
- #156 - cached findAll pending query doesn't get removed sometimes

dist/angular-data.js

+5
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,8 @@ function DSHttpAdapterProvider() {
16591659
return params;
16601660
},
16611661

1662+
forceTrailingSlash: false,
1663+
16621664
/**
16631665
* @doc property
16641666
* @id DSHttpAdapterProvider.properties:defaults.$httpConfig
@@ -1719,6 +1721,9 @@ function DSHttpAdapterProvider() {
17191721
HTTP: function (config) {
17201722
var start = new Date().getTime();
17211723

1724+
if (this.defaults.forceTrailingSlash && config.url[config.url.length] !== '/') {
1725+
config.url += '/';
1726+
}
17221727
config = DSUtils.deepMixIn(config, defaults.$httpConfig);
17231728
return $http(config).then(function (data) {
17241729
$log.debug(data.config.method + ' request:' + data.config.url + ' Time taken: ' + (new Date().getTime() - start) + 'ms', arguments);

dist/angular-data.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/adapters/http.js

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function DSHttpAdapterProvider() {
4343
return params;
4444
},
4545

46+
forceTrailingSlash: false,
47+
4648
/**
4749
* @doc property
4850
* @id DSHttpAdapterProvider.properties:defaults.$httpConfig
@@ -103,6 +105,9 @@ function DSHttpAdapterProvider() {
103105
HTTP: function (config) {
104106
var start = new Date().getTime();
105107

108+
if (this.defaults.forceTrailingSlash && config.url[config.url.length] !== '/') {
109+
config.url += '/';
110+
}
106111
config = DSUtils.deepMixIn(config, defaults.$httpConfig);
107112
return $http(config).then(function (data) {
108113
$log.debug(data.config.method + ' request:' + data.config.url + ' Time taken: ' + (new Date().getTime() - start) + 'ms', arguments);

test/integration/datastore/async_methods/create.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ describe('DS.create(resourceName, attrs[, options])', function () {
4343
assert.deepEqual(DS.get('post', 5), p1);
4444
});
4545
it('should create an item and save it to the server but not inject the result', function () {
46-
$httpBackend.expectPOST('http://test.angular-cache.com/posts').respond(200, p1);
46+
DSHttpAdapter.defaults.forceTrailingSlash = true;
47+
$httpBackend.expectPOST('http://test.angular-cache.com/posts/').respond(200, p1);
4748

4849
DS.create('post', { author: 'John', age: 30 }, { cacheResponse: false }).then(function (post) {
4950
assert.deepEqual(post, p1, 'post 5 should have been created');
@@ -53,6 +54,7 @@ describe('DS.create(resourceName, attrs[, options])', function () {
5354
});
5455

5556
$httpBackend.flush();
57+
DSHttpAdapter.defaults.forceTrailingSlash = false;
5658

5759
assert.equal(lifecycle.beforeCreate.callCount, 1, 'beforeCreate should have been called');
5860
assert.equal(lifecycle.afterCreate.callCount, 1, 'afterCreate should have been called');

0 commit comments

Comments
 (0)