I have configured both primus and restful service on my feathersjs server. Below is the configuration code.
app
.use(compress())
.options('*', cors())
.use(cors())
.use('/', serveStatic(app.get('public')))
.use(bodyParser.json())
.use(bodyParser.urlencoded({extended: true}))
.configure(hooks())
.configure(rest())
.configure(swagger({
docsPath: '/docs',
uiIndex: path.join(__dirname, '../public/docs.html'),
info: {
title: process.env.npm_package_fullName,
description: process.env.npm_package_description
}
}))
.configure(primus({
transformer: 'websockets',
timeout: false
}, (primus) => {
primus.library();
primus.save(path.join(__dirname, '../public/dist/primus.js'));
}))
On client side, below is the code to use Primus as the connection method which is websocket in this case. How can I use restful on client side in this case? The service methods defined in feathersjs are same for websocket and restful. How can I make a specific restful call instead of websocket?
const feathers = require('feathers-client');
const rest = require('feathers-rest/client');
const Primus = require('../public/dist/primus.js');
let primus = new Primus('http://localhost:3030');
let app = feathers()
.configure(feathers.hooks())
.configure(feathers.primus(primus));
I have read the instruction from https://docs.feathersjs.com/clients/rest.html and I know how to request rest or websocket connection separately. I don't know how to combine them into one client side.
You shouldn't have to. Feathers works completely through either REST or Websockets, there is no need to use both in the same app. Normally we recommend the Websocket connection if possible since you will also get real-time events and requests are faster once the connection is established.
What the connection configuration on the client really does is initialize a standard service that uses the connection to talk to a remote service when app.service('anything') is called. If absolutely necessary you can import and instantiate one of the REST clients and register it as a service on your app manually:
const SuperAgentClient = require('feathers-rest/lib/client/superagent');
const superagent = require('superagent');
app.use('/myservice', new SuperAgentClient({
name: 'servicename',
connection: superagent,
base: 'http://my-server.com'
}));
Related
I am trying to validate my access token (not JWT) with LoginRadius, I can do the login but after when I call my API I always get unauthorized or different errors according to my Authentication configuration, I am using like this. I believe the authority url is not correct but I couldn't find any other
services.AddAuthentication(options => {
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect("login-radius", options => {
// Set the authority to your Auth0 domain
options.Authority = $"https://api.loginradius.com/identity/v2/auth/";
// Configure the Auth0 Client ID and Client Secret
options.ClientId = Configuration["ClientId"];
options.ClientSecret = Configuration["ClientSecret"];
// Set response type to code
options.ResponseType = OpenIdConnectResponseType.Code;
options.Scope.Clear();
options.Scope.Add("openid");
options.CallbackPath = new PathString("/callback");
options.ClaimsIssuer = "loginradius";
// Saves tokens to the AuthenticationProperties
options.SaveTokens = true;
});
I believe you are trying to setup OIDC, and to configure it, please refer to the LoginRadius docs on OIDC, as it needs few things that need to be configured in the Admin Console and the correct authority URL: https://www.loginradius.com/docs/single-sign-on/tutorial/federated-sso/openid-connect/openid-connect-overview/#otheropenidfunctionality6
Please refer to the OIDC discovery endpoint, which provides a client with configuration details about the OpenID Connect metadata of the Loginradius App.
URL Format: https://cloud-api.loginradius.com/sso/oidc/v2/{sitename}/{oidcappname}/.well-known/openid-configuration
My account didn't have access to few features
I have this code in index.js:
const PORT = process.env.PORT || 5000;
server.listen(PORT).then({ url }) => {
console.log(`Server running at url: ${url}`);
});
In local development, when I went to localhost:5000 on my browser, I could test with the GraphQL playground.
Now, I just finished deploying with Heroku. When I go to my URL, I see:
GET query missing. I assume this happens because apollo is trying to open the GraphQL playground, but it is blocked in production mode.
How can I tell apollo to serve client/index.html instead?
Note: I tried putting index.html in the root directory as well, but nothing changed.
I saw in a tutorial video that the answer to this question in express is:
app.use(express.static('client'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client','index.html'));
});
I don't know how to do this in Apollo.
The standalone Apollo Server cannot be used for serving static files or exposing other endpoints. If you need this functionality, you need to use an HTTP framework like Express, Hapi or Koa and then use the appropriate Apollo Server integration.
Example using Express:
const server = new ApolloServer({ ... });
const app = express();
server.applyMiddleware({ app });
app.listen({ port: 4000 }, () =>
console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`)
);
I am working on a task that uploads image to SFTP server with Firebase Function. But the image source is not from my local computer but a http URL such as https://image.com/abc.jpg. I am using ssh2-sftp-client npm package. Currently I am using my mac both for client and server and it is working fine when I am accessing local file(/Users/shared/abc.jpeg) and uploading it to local server(/Uesrs/shared/sftp-server/abc.jpeg). But when I tried to have access to https://image.com/abc.jpg. and upload it to local server I got the error that says "ENOENT: no such file or directory/ ...". And below is my code
const functions = require('firebase-functions');
let Client = require('ssh2-sftp-client');
exports.sftpTest = functions.https.onRequest((request, response) => {
let sftp = new Client();
const config = {
host: '192.***.***.***',
port: '22',
username: '****',
password: '****'
}
let localFile = 'https://images.unsplash.com/photo-1487260211189-670c54da558d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=934&q=80';
let remoteFile = '/Users/Shared/unsplash.JPG';
sftp.connect(config)
.then(() => {
sftp.fastPut(localFile, remoteFile);
})
.catch(err => {
console.error(err.message);
});
});
My first time to have access to sftp server and anyone's advice will be much appreciated.
The method you are using from this library does not support usage in the way you are trying to set it up. the method fastPut usually is to upload local files to a remote server, I think you should use the fastGet method in order to download files from a remote server, however, please note that there are no notes that indicate that you can use these methods with the URL in the way you are trying to achieve.
I maked follow:
feathers g app # with socket and rest
feathers g service # todos & NeDB
npm start
and simple client for this. I copy code from documentation
https://docs.feathersjs.com/api/client/socketio.
const feathers = require('#feathersjs/feathers');
const socketio = require('#feathersjs/socketio-client');
const io = require('socket.io-client');
const socket = io('http://localhost:3030');
const app = feathers();
app.configure(socketio(socket));
app.service('todos')
.on('created', message => console.log('New message created', message));
app.service('todos').find().then(r => {
console.log(r)
}).catch(e => console.log('error',e))
app.service('todos').create({
title: 'A message from a REST client'
});
this client code get me timeout errors for find() and create() methods
But if I make POST request by CURL, I have onCreated message in console
Why I got errors on create() and find() calls?
UPDATE:
I maked git repo for easy reproduce this problem
https://github.com/tolyanor/feathersjs-error
UPDATE2:
I change autogenerated file src/app.js like in feathers example chat application https://github.com/feathersjs/feathers-chat/blob/master/src/app.js
Now I CAN call service method create on client, but CAN NOT receive onCreated message. So, this code
app.service('/todos')
.on('created', message => console.log('New todos created', message));
never calling
You are using a Feathers v3 client with a Feathers v2 server. Old clients will be backwards compatible with new servers but not the other way around. Follow the migration guide to upgrade your server or generate a new application using #feathersjs/cli (feathers --version on the command line should show v3.5.0 or later).
I use below code to generate featherjs-primus client js file. But the primus function is not called until I call app.listen(). Is there a way for me to generate this file without start the server?
app
.configure(primus({
transformer: 'websockets',
timeout: false
}, (primus) => {
const lib = primus.library();
primus.save(path.join(__dirname, '../public/dist/primus.test.js'));
}))
You can call app.setup instead of app.listen to run that callback. The websocket providers will however need an HTTP server passed to app.setup. More information can be found in the middleware chapter.