Created
March 24, 2018 13:11
-
-
Save sean-nicholas/b24c59d9c19a102d7a7035956a18e719 to your computer and use it in GitHub Desktop.
feathers-reactive with Angular Universal - data 3
This file contains hidden or 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
| import { Injectable, PLATFORM_ID, Inject } from '@angular/core' | |
| import { isPlatformBrowser } from '@angular/common' | |
| import { HttpClient, HttpHeaders } from '@angular/common/http' | |
| import { rxUniversal } from '../../lib/rx-universal' | |
| import feathers from '@feathersjs/feathers' | |
| import rest from '@feathersjs/rest-client' | |
| import socketio from '@feathersjs/socketio-client' | |
| import * as rx from 'feathers-reactive' | |
| import * as io from 'socket.io-client' | |
| @Injectable() | |
| export class DataService { | |
| constructor( | |
| @Inject(PLATFORM_ID) private platformId: Object, | |
| private http: HttpClient | |
| ) { | |
| if (isPlatformBrowser(this.platformId)) { | |
| const socket = io(this.BASE_URL) | |
| this.app | |
| .configure(socketio(socket)) | |
| .configure(rx({ idField: '_id' })) | |
| } else { | |
| const restClient = rest(this.BASE_URL) | |
| this.app | |
| .configure(restClient.angularHttpClient(http, { HttpHeaders: HttpHeaders })) | |
| .configure(rxUniversal()) | |
| } | |
| } | |
| BASE_URL = 'SOME_URL' | |
| app = feathers() as Application<Services> | |
| products() { | |
| return this.app.service('products').watch().find() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment