You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can access cookies for the current request via `fastboot.request` in the `fastboot` service.
144
151
145
152
```javascript
146
-
exportdefaultEmber.Route.extend({
147
-
fastboot:Ember.inject.service(),
153
+
importRoutefrom'@ember/routing/route';
154
+
import { injectasservice } from'@ember/service';
155
+
156
+
exportdefaultRoute.extend({
157
+
fastboot:service(),
148
158
149
159
model() {
150
160
let authToken =this.get('fastboot.request.cookies.auth');
@@ -162,11 +172,14 @@ The `host` property will return the full `hostname` and `port` (`example.com` or
162
172
For example, when requesting `http://myapp.example.com/photos` from your browser, `fastboot.request.host` would equal `myapp.example.com`
163
173
164
174
```javascript
165
-
exportdefaultEmber.Route.extend({
166
-
fastboot:Ember.inject.service(),
175
+
importRoutefrom'@ember/routing/route';
176
+
import { injectasservice } from'@ember/service';
177
+
178
+
exportdefaultRoute.extend({
179
+
fastboot:service(),
167
180
168
181
model() {
169
-
let host =this.get('fastboot.request.host');
182
+
let host =this.fastboot.request.host;
170
183
// ...
171
184
}
172
185
});
@@ -215,11 +228,14 @@ An improperly constructed `RegExp` could open your FastBoot servers and any back
215
228
You can access query parameters for the current request via `fastboot.request` in the `fastboot` service.
216
229
217
230
```javascript
218
-
exportdefaultEmber.Route.extend({
219
-
fastboot:Ember.inject.service(),
231
+
importRoutefrom'@ember/routing/route';
232
+
import { injectasservice } from'@ember/service';
233
+
234
+
exportdefaultRoute.extend({
235
+
fastboot:service(),
220
236
221
237
model() {
222
-
let authToken =this.get('fastboot.request.queryParams.auth');
238
+
let authToken =this.fastboot.request.queryParams.auth;
223
239
// ...
224
240
}
225
241
});
@@ -232,11 +248,14 @@ The service's `queryParams` property is an object containing the request's query
232
248
You can access the path (`/` or `/some-path`) of the request that the current FastBoot server is responding to via `fastboot.request` in the `fastboot` service.
You can access the protocol (`http:` or `https:`) of the request that the current FastBoot server is responding to via `fastboot.request` in the `fastboot` service.
248
267
249
268
```javascript
250
-
exportdefaultEmber.Route.extend({
251
-
fastboot:Ember.inject.service(),
269
+
importRoutefrom'@ember/routing/route';
270
+
import { injectasservice } from'@ember/service';
271
+
272
+
exportdefaultRoute.extend({
273
+
fastboot:service(),
252
274
253
275
model() {
254
-
let protocol =this.get('fastboot.request.protocol');
276
+
let protocol =this.fastboot.request.protocol;
255
277
// ...
256
278
}
257
279
});
@@ -263,11 +285,14 @@ You can also access the method of the request via `fastboot.request` in the `fas
263
285
The `method` property will return the method name (`GET`, `POST`, `PATCH`...) of the request.
264
286
265
287
```javascript
266
-
exportdefaultEmber.Route.extend({
267
-
fastboot:Ember.inject.service(),
288
+
importRoutefrom'@ember/routing/route';
289
+
import { injectasservice } from'@ember/service';
290
+
291
+
exportdefaultRoute.extend({
292
+
fastboot:service(),
268
293
269
294
model() {
270
-
let method =this.get('fastboot.request.method');
295
+
let method =this.fastboot.request.method;
271
296
// ...
272
297
}
273
298
});
@@ -341,11 +366,14 @@ Depending on what method on `body-parser` you used, the body can be a parse JSON
341
366
or even a raw Buffer.
342
367
343
368
```javascript
344
-
exportdefaultEmber.Route.extend({
345
-
fastboot:Ember.inject.service(),
369
+
importRoutefrom'@ember/routing/route';
370
+
import { injectasservice } from'@ember/service';
371
+
372
+
exportdefaultRoute.extend({
373
+
fastboot:service(),
346
374
347
375
model() {
348
-
let method =this.get('fastboot.request.body');
376
+
let method =this.fastboot.request.body;
349
377
// ...
350
378
}
351
379
});
@@ -361,14 +389,17 @@ You can access the current response headers via `fastboot.response.headers`.
361
389
The `headers` object implements part of the [Fetch API's Headers class](https://developer.mozilla.org/en-US/docs/Web/API/Headers), the functions available are [`has`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/has), [`get`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/get), and [`getAll`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/getAll).
362
390
363
391
```javascript
364
-
exportdefaultEmber.Route.extend({
365
-
fastboot:Ember.inject.service(),
392
+
importRoutefrom'@ember/routing/route';
393
+
import { injectasservice } from'@ember/service';
394
+
395
+
exportdefaultRoute.extend({
396
+
fastboot:service(),
366
397
367
398
model() {
368
-
let isFastBoot =this.get('fastboot.isFastBoot');
399
+
let isFastBoot =this.fastboot.isFastBoot;
369
400
370
401
if (isFastBoot) {
371
-
let resHeaders =this.get('fastboot.response.headers');
@@ -383,18 +414,21 @@ This is useful if you want your application to return a non-default (`200`) stat
383
414
For example if you want a route of your application to be `401 - Unauthorized` if it accessed without OAuth credentials, you could use `statusCode` to do that.
384
415
385
416
```javascript
386
-
exportdefaultEmber.Route.extend({
387
-
fastboot:Ember.inject.service(),
417
+
importRoutefrom'@ember/routing/route';
418
+
import { injectasservice } from'@ember/service';
419
+
420
+
exportdefaultRoute.extend({
421
+
fastboot:service(),
388
422
389
423
beforeModel() {
390
-
let isFastBoot =this.get('fastboot.isFastBoot');
424
+
let isFastBoot =this.fastboot.isFastBoot;
391
425
392
426
if (!isFastBoot) {
393
427
return;
394
428
}
395
429
396
-
let reqHeaders =this.get('fastboot.request.headers');
397
-
let authHeaders =reqHeaders.get('Authorization');
430
+
let reqHeaders =this.fastboot.request.headers;
431
+
let authHeaders =reqHeaders.Authorization;
398
432
399
433
if (authHeaders ===null) {
400
434
this.set('fastboot.response.statusCode', 401);
@@ -467,13 +501,16 @@ In the example below, we find and store our data in a `shoeboxStore` object, whe
467
501
When the same code is then executed by the client browser, we retrieve the items from the `shoeboxStore` rather than redoing the find (and triggering a network request).
0 commit comments