Skip to content

Instantly share code, notes, and snippets.

@sean-nicholas
Created March 24, 2018 13:11
Show Gist options
  • Select an option

  • Save sean-nicholas/b24c59d9c19a102d7a7035956a18e719 to your computer and use it in GitHub Desktop.

Select an option

Save sean-nicholas/b24c59d9c19a102d7a7035956a18e719 to your computer and use it in GitHub Desktop.
feathers-reactive with Angular Universal - data 3
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