loopbackjs

Using custom Loopback user model with loopback-component-passport

穿精又带淫゛_ 提交于 2019-11-30 18:04:20
问题 I'm trying to use a extended loopback user model together with the loopback-component-passport for facebook login. The login itself is working but i can't get it to use my custom user model instead of the builtin "Users". steps i took: - create custom user model with slc loopback:model extending "User" { "name": "myuser", "plural": "myusers", "base": "User", "idInjection": true, "options": { "validateUpsert": true }, "properties": { "mytestproperty": { "type": "string", "default":

File Upload With Loopback

与世无争的帅哥 提交于 2019-11-30 16:25:18
I created a Simple file uploading Application with loopback. Application client side i used simple html and Java Script code . i calling a loopback api with ajax call , this is Java Script code - $('#upload-input').on('change', function () { var files = $(this).get(0).files; if (files.length > 0) { // One or more files selected, process the file upload var form = new FormData(); for (var index = 0; index < files.length; index++) { var file = files[index]; form.append('Uploded Files', file, file.name); } $.ajax({ url: 'api/fileupload/upload', type: 'POST', data: form, processData: false,

Store session in operation hook - Loopback

拥有回忆 提交于 2019-11-30 09:55:38
问题 I want to store some data other than userId or accessToken to store in a session, in after save or before save operation hook in Loopback application using express-session . I have this in my server/server.js : .... const session = require('express-session'); const MongoStore = require('connect-mongo')(session); .... app.use(session({ name:'session-name', secret: 'keyboard cat', store: new MongoStore({url: 'mongodb://localhost/test', ttl:1}), resave: false, saveUninitialized: true })); And as

How to run multiple StrongLoop LoopBack apps on the same server?

自作多情 提交于 2019-11-30 07:34:26
I'm currently running two StrongLoop LoopBack apps (Nodejs apps) on a single server with different ports. Both apps were created using slc lb project and slc lb model from the command line. Is it possible to run these apps on a single ports with different path and/or subdomain? If it is, how do I do that on a Linux machine? Example: http://api.server.com:3000/app1/ for first app. http://api.server.com:3000/app2/ for second app. thanks. Since LoopBack applications are regular Express applications, you can mount them on a path of the master app. var app1 = require('path/to/app1'); var app2 =

Dynamic Properties or Aggregate Functions in Loopback Models

醉酒当歌 提交于 2019-11-30 07:14:18
How would I go about using aggregate functions in Loopback models? If I have a model backed by a mysql database, could I have Model1 with a hasMany relation to Model2 (with a given numeric property), and have a property in Model1 that grabs the SUM of that field from Model2? { "Model1" : { "Relations" : { "model2s" : { "type": "hasMany", "model": "Model2", "foreignKey": "model1Id" } }, "Properties" : { "total" : { "type": "Number" [SUM of Model2 'amount' field] } } }, "Model2" : { "Relations" : { "model1s" : { "type": "belongsTo", "model": "Model1", "foreignKey": "model1Id" } }, "Properties" :

Execute raw query on MySQL Loopback Connector

北慕城南 提交于 2019-11-30 07:12:27
How is it possible to execute raw query and expose results through REST API with strongloop? I've read something about using hooks and dataSource.connector.query() but I cannot find any working examples. Here is a basic example. If you have a Product model (/common/models/product.json), extend the model by adding a /common/models/product.js file: module.exports = function(Product) { Product.byCategory = function (category, cb) { var ds = Product.dataSource; var sql = "SELECT * FROM products WHERE category=?"; ds.connector.query(sql, category, function (err, products) { if (err) console.error

Destroy a model in loopback.io

你。 提交于 2019-11-30 06:14:07
How can I delete a model in strongloop's loopback.io? I have seen somewhere command called persistedModel.destroy() but when I exectute slc persistedModel.destroy() I get command not found error. Delete /common/models/your-model.js and /common/models/your-model.json , then delete the lines referencing your model in /server/model-config.json . 来源: https://stackoverflow.com/questions/28512991/destroy-a-model-in-loopback-io

File Upload With Loopback

℡╲_俬逩灬. 提交于 2019-11-30 00:08:04
问题 I created a Simple file uploading Application with loopback. Application client side i used simple html and Java Script code . i calling a loopback api with ajax call , this is Java Script code - $('#upload-input').on('change', function () { var files = $(this).get(0).files; if (files.length > 0) { // One or more files selected, process the file upload var form = new FormData(); for (var index = 0; index < files.length; index++) { var file = files[index]; form.append('Uploded Files', file,

NodeJS Request Post not working for HTTPS website

有些话、适合烂在心里 提交于 2019-11-29 16:41:46
Im using NodeJS Request - Simplified HTTP Client I seem to have problem working with HTTPS website, I am not getting result. var request = require('request'); request.post({ url: "",//your url headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, form: { myfield: "myfieldvalue" } },function (response, err, body){ console.log('Body:',JSON.parse(body)); }.bind(this)); Tested the API endpoint(which I cant share) on Postman, I just turn off SSL and it works, how do I do the same with request plugin? Just add this lines: rejectUnauthorized: false,//add when working with https sites

LoopbackJS: HasAndBelongsToMany, how to query/filter by property of relation?

前提是你 提交于 2019-11-29 15:33:38
I'm currently working on my first Loopbackjs project and am facing a seemingly simple issue: Let's say I have a model "Post" and a model "Tag". A Post has and belongs to many tags. Now I need to list all posts with specific tags. I just can't figure out how to create a query with Loopback that achieves this. I thought it would work something like this, but it doesn't: Posts.find( {where: {tag.id: {inq: [1, 4]}}} ); I would greatly appreciate any help. It's not as easy as it should be to carry out a filter on some related properties. There is a pull request outstanding but it's been open for a