Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

How to access feathers-client #102

Closed
nicoknoll opened this issue Oct 23, 2016 · 7 comments
Closed

How to access feathers-client #102

nicoknoll opened this issue Oct 23, 2016 · 7 comments

Comments

@nicoknoll
Copy link
Contributor

nicoknoll commented Oct 23, 2016

Hey,
this is not really an issue but probably me misunderstanding some part of the concept of feathers-client.

So what I want to have is a feathers server and a separate client with react. The server ist working fine and I can connect to the feathers services running on the server from client with socket = io('http://localhost:3030/').

But what I don't get is how I can access the client in the browser now. I tried to setup routes with app.use but then I get the error Middleware functions can not be used in the Feathers client.

So how can I setup routes and define the port on which I can access the client (app.listen(port) isn't doing anything as well)?

@marshallswain
Copy link
Member

marshallswain commented Oct 23, 2016

Feathers client is intended to help you get connected to your Feathers server's services. You don't need routes, you just create services with URLs that match the ones you created on the server.

var feathers = require('feathers/client');
var io = require('socket.io-client/socket.io');
var socketio = require('feathers-socket.io/client');
var hooks = require('feathers-hooks');
var auth = require('feathers-authentication/client');

var socket = io('http://localhost:3030', {
 transports: ['websocket']
});
var app = feathers()
 .configure(socketio(socket))
 .configure(hooks())
 .configure(auth());

var messageService = app.service('/match/the/server/url/for/messages');

messageService.find({query:{put query here}}).then(function(response){
// Messages will be at response.data if you have pagination turned on.
// Otherwise response will be an array of messages.
});

@daffl
Copy link
Member

daffl commented Oct 23, 2016

One additional note is that the client only lets you connect to Feathers services not any other custom routes you have registered. Basic Express routes are only available via HTTP and a client like request.

@nicoknoll
Copy link
Contributor Author

Okay, thanks so far!

So if I want to build a normal webapp with views and custom urls I have to use something like express for routes and views and feathers client for sending events to my feathers server and receiving events from it?

@corymsmith
Copy link
Contributor

@nicoknoll Depends what you mean by "normal webapp", you can use feathers-client from React to communicate with your Feathers API as well. Or as you had mentioned you can render views from the server using express then once loaded fetch data using feathers-client. If you're rendering from the server you can also fetch data from your feathers services on the server and use that data when rendering your templates.

@nicoknoll
Copy link
Contributor Author

Okay, I think I got it. Big thanks to anyone.

I think I was just confused by the var naming of var app = feathers() in the sample as "app" is for me normally a feathers or express instance. var server = feathers() would maybe be more clear :)

@corymsmith
Copy link
Contributor

Agreed about the naming potentially being confusing, something like:
var apiClient = feathers()
or
var client = feathers()

may make more sense since server may add even more confusion

nicoknoll added a commit to nicoknoll/feathers-client that referenced this issue Oct 24, 2016
This should help people like me who could get confused by having "feathersClient" called "app" but not being able to use it as "app" in feathers (not client) or express.

Regarding: feathersjs-ecosystem#102
daffl pushed a commit that referenced this issue Oct 25, 2016
* Change variable naming from "app" to "feathersClient"

This should help people like me who could get confused by having "feathersClient" called "app" but not being able to use it as "app" in feathers (not client) or express.

Regarding: #102

* client instead of feathersClient
@daffl
Copy link
Member

daffl commented Oct 25, 2016

Closed via #103, thank you!

@daffl daffl closed this as completed Oct 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants