-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
220 additions
and
3 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
packages/ember-cli-fastboot/fastboot/instance-initializers/fetch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function initialize(instance) { | ||
let { request } = instance.lookup('service:fastboot'); | ||
fetch.__fastbootRequest = request; | ||
} | ||
|
||
export default { | ||
name: 'fastboot:fetch', // `ember-fetch` addon registers as `fetch` | ||
initialize, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Route from '@ember/routing/route'; | ||
import { assert } from '@ember/debug'; | ||
|
||
export default class FetchRoute extends Route { | ||
beforeModel() { | ||
assert('fetch is available', fetch); | ||
assert('Request is available', Request); | ||
assert('Response is available', Response); | ||
assert('Headers is available', Headers); | ||
assert('AbortController is available', AbortController); | ||
} | ||
|
||
async model() { | ||
let responses = await Promise.all([ | ||
fetch('http://localhost:45678/absolute-url.json'), | ||
fetch(new Request('http://localhost:45678/absolute-request.json')), | ||
fetch('//localhost:45678/protocol-relative-url.json'), | ||
fetch(new Request('//localhost:45678/protocol-relative-request.json')), | ||
fetch('/path-relative-url.json'), | ||
fetch(new Request('/path-relative-request.json')), | ||
]); | ||
|
||
responses = await Promise.all(responses.map((response) => response.json())); | ||
|
||
return responses.map((response) => response.response).join('|'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{@model}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"response": "absolute-request" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"response": "absolute-url" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"response": "path-relative-request" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"response": "path-relative-url" | ||
} |
3 changes: 3 additions & 0 deletions
3
test-packages/basic-app/public/protocol-relative-request.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"response": "protocol-relative-request" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"response": "protocol-relative-url" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
const RSVP = require('rsvp'); | ||
const request = RSVP.denodeify(require('request')); | ||
const expect = require('chai').use(require('chai-string')).expect; | ||
const { startServer, stopServer } = require('../../test-libs'); | ||
|
||
describe('fetch', function () { | ||
this.timeout(120000); | ||
|
||
before(function () { | ||
return startServer(); | ||
}); | ||
|
||
after(function () { | ||
return stopServer(); | ||
}); | ||
|
||
it('uses fetch', async () => { | ||
const response = await request({ | ||
url: 'http://localhost:45678/fetch', | ||
headers: { | ||
Accept: 'text/html', | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).to.equal(200); | ||
expect(response.headers['content-type']).to.equalIgnoreCase('text/html; charset=utf-8'); | ||
expect(response.body).to.contain( | ||
[ | ||
'absolute-url', | ||
'absolute-request', | ||
'protocol-relative-url', | ||
'protocol-relative-request', | ||
'path-relative-url', | ||
'path-relative-request', | ||
].join('|') | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters