Skip to content

Commit 9bfe889

Browse files
authored
Merge pull request #53 from xsnippet/preserve-protocol
Preserve communication protocol in requests to API
2 parents 8ed97ef + ad820c8 commit 9bfe889

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/actions/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const fetchRecentSnippets = marker => (dispatch) => {
1414
let qs = '';
1515
if (marker) { qs = `&marker=${marker}`; }
1616

17-
return fetch(`http://api.xsnippet.org/snippets?limit=20${qs}`)
17+
return fetch(`//api.xsnippet.org/snippets?limit=20${qs}`)
1818
.then((response) => {
1919
const links = parseLinkHeader(response.headers.get('Link'));
2020

@@ -30,7 +30,7 @@ export const setSnippet = snippet => ({
3030
});
3131

3232
export const fetchSnippet = id => dispatch => (
33-
fetch(`http://api.xsnippet.org/snippets/${id}`)
33+
fetch(`//api.xsnippet.org/snippets/${id}`)
3434
.then(response => response.json())
3535
.then(json => dispatch(setSnippet(json)))
3636
);
@@ -41,13 +41,13 @@ export const setSyntaxes = syntaxes => ({
4141
});
4242

4343
export const fetchSyntaxes = dispatch => (
44-
fetch('http://api.xsnippet.org/syntaxes')
44+
fetch('//api.xsnippet.org/syntaxes')
4545
.then(response => response.json())
4646
.then(json => dispatch(setSyntaxes(json)))
4747
);
4848

4949
export const postSnippet = (snippet, onSuccess) => dispatch => (
50-
fetch('http://api.xsnippet.org/snippets', {
50+
fetch('//api.xsnippet.org/snippets', {
5151
method: 'POST',
5252
headers: {
5353
'Accept': 'application/json',

tests/store.test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ describe('actions', () => {
4444
first: {
4545
limit: '20',
4646
rel: 'first',
47-
url: 'http://api.xsnippet.org/snippets?limit=20',
47+
url: '//api.xsnippet.org/snippets?limit=20',
4848
},
4949
next: {
5050
limit: '20',
5151
marker: 28,
5252
rel: 'next',
53-
url: 'http://api.xsnippet.org/snippets?limit=20&marker=28',
53+
url: '//api.xsnippet.org/snippets?limit=20&marker=28',
5454
},
5555
prev: {
5656
limit: '20',
5757
rel: 'prev',
58-
url: 'http://api.xsnippet.org/snippets?limit=20',
58+
url: '//api.xsnippet.org/snippets?limit=20',
5959
},
6060
};
6161
const store = createStore();
@@ -82,10 +82,10 @@ describe('actions', () => {
8282
syntax: 'Python',
8383
},
8484
];
85-
const links = '<http://api.xsnippet.org/snippets?limit=20>; rel="first", <http://api.xsnippet.org/snippets?limit=20&marker=19>; rel="next", <http://api.xsnippet.org/snippets?limit=20&marker=59>; rel="prev"';
85+
const links = '<//api.xsnippet.org/snippets?limit=20>; rel="first", <//api.xsnippet.org/snippets?limit=20&marker=19>; rel="next", <//api.xsnippet.org/snippets?limit=20&marker=59>; rel="prev"';
8686

8787
fetchMock.getOnce(
88-
'http://api.xsnippet.org/snippets?limit=20&marker=39',
88+
'//api.xsnippet.org/snippets?limit=20&marker=39',
8989
{
9090
headers: { Link: links },
9191
body: snippets,
@@ -114,19 +114,19 @@ describe('actions', () => {
114114
first: {
115115
limit: '20',
116116
rel: 'first',
117-
url: 'http://api.xsnippet.org/snippets?limit=20',
117+
url: '//api.xsnippet.org/snippets?limit=20',
118118
},
119119
next: {
120120
limit: '20',
121121
marker: '19',
122122
rel: 'next',
123-
url: 'http://api.xsnippet.org/snippets?limit=20&marker=19',
123+
url: '//api.xsnippet.org/snippets?limit=20&marker=19',
124124
},
125125
prev: {
126126
limit: '20',
127127
marker: '59',
128128
rel: 'prev',
129-
url: 'http://api.xsnippet.org/snippets?limit=20&marker=59',
129+
url: '//api.xsnippet.org/snippets?limit=20&marker=59',
130130
},
131131
},
132132
});
@@ -145,10 +145,10 @@ describe('actions', () => {
145145
syntax: 'Python',
146146
},
147147
];
148-
const links = '<http://api.xsnippet.org/snippets?limit=20>; rel="first", <http://api.xsnippet.org/snippets?limit=20&marker=39>; rel="next"';
148+
const links = '<//api.xsnippet.org/snippets?limit=20>; rel="first", <//api.xsnippet.org/snippets?limit=20&marker=39>; rel="next"';
149149

150150
fetchMock.getOnce(
151-
'http://api.xsnippet.org/snippets?limit=20',
151+
'//api.xsnippet.org/snippets?limit=20',
152152
{
153153
headers: { Link: links },
154154
body: snippets,
@@ -177,13 +177,13 @@ describe('actions', () => {
177177
first: {
178178
limit: '20',
179179
rel: 'first',
180-
url: 'http://api.xsnippet.org/snippets?limit=20',
180+
url: '//api.xsnippet.org/snippets?limit=20',
181181
},
182182
next: {
183183
limit: '20',
184184
marker: '39',
185185
rel: 'next',
186-
url: 'http://api.xsnippet.org/snippets?limit=20&marker=39',
186+
url: '//api.xsnippet.org/snippets?limit=20&marker=39',
187187
},
188188
},
189189
});
@@ -219,7 +219,7 @@ describe('actions', () => {
219219
syntax: 'Go',
220220
};
221221

222-
fetchMock.getOnce(`http://api.xsnippet.org/snippets/${snippet.id}`, JSON.stringify(snippet));
222+
fetchMock.getOnce(`//api.xsnippet.org/snippets/${snippet.id}`, JSON.stringify(snippet));
223223

224224
const store = createStore();
225225
await store.dispatch(actions.fetchSnippet(snippet.id));
@@ -254,7 +254,7 @@ describe('actions', () => {
254254
it('should create an action to fetch syntaxes', async () => {
255255
const syntaxes = ['JavaScript', 'Python', 'Java', 'Go', 'Plain Text'];
256256

257-
fetchMock.getOnce('http://api.xsnippet.org/syntaxes', JSON.stringify(syntaxes));
257+
fetchMock.getOnce('//api.xsnippet.org/syntaxes', JSON.stringify(syntaxes));
258258

259259
const store = createStore();
260260
await store.dispatch(actions.fetchSyntaxes);
@@ -274,7 +274,7 @@ describe('actions', () => {
274274
syntax: 'JavaScript',
275275
};
276276

277-
fetchMock.postOnce('http://api.xsnippet.org/snippets', JSON.stringify(snippet));
277+
fetchMock.postOnce('//api.xsnippet.org/snippets', JSON.stringify(snippet));
278278

279279
const store = createStore();
280280
await store.dispatch(actions.postSnippet(snippet, () => {}));

0 commit comments

Comments
 (0)