LoopBack is an open source Node.js framework built on top of Express optimized for mobile, web, and other devices. Connect to multiple data sources, write business logic in Node.js, glue on top of your existing services and data, connect using JS, iOS & Android SDKs.
bajtos on add-node10
Hi
I am using loopback 4 for backend and react for front end.
when I make a request on API, it gives me blocked Cors.
I tried this :
let config = {
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
},
redirect: 'follow',
referrerPolicy: 'no-referrer',
}
const response = await axios.post(${API}/signUppatient
, obj, config);
but it didn't work
const config = {
name: 'ipfs',
connector: 'rest',
baseURL: 'http://localhost:5001/api/v0/',
crud: false,
operations: [
{
template: {
method: 'POST',
url: 'http://localhost:5001/api/v0/add',
headers: {
'content-type': 'multipart/form-data;'
},
query: {
'only-hash': true,
},
form: {
file: '{file}',
},
},
functions: {
getCID: ['file'],
},
},
{
template: {
method: 'POST',
url: 'http://localhost:5001/api/v0/bootstrap/list',
},
functions: {
getPeers: [],
},
},
],
};
export interface Ipfs {
getCID(file: Buffer): Promise<CID>,
getPeers(): Promise<unknown>
}
allowArray
in an option somewhere. However, I have not found where this option should be inserted. In the model json description I assume, but where?
To help encourage and foster an open community, the GitHub Discussions tab has been enabled. Engage in Q&As, Idea Proposals, or showcase your extensions and projects using LB4.
GitHub Discussions will work alongside Slack to help increase community reach and interaction, and both are actively monitored by the LoopBack 4 Maintainers.
See you there!
GitHub Discussions: https://github.com/strongloop/loopback-next/discussions/7155
Slack: https://loopback.io navbar or strongloop/loopback-next#5048.
Hey Guys, slowly I'm getting frustrated, maybe you can help me out. My problem might be more of a TypeScript problem than a lb4 problem, but maybe you ran into this too.
I built a controller to download a file, like described here: https://loopback.io/doc/en/lb4/File-upload-download.html
Thus I'm injecting the response into my function. Now I'm trying to write a unit test for the controller and am trying to create a stubInstance for the response object which is expected by the function with sinon, but Typescript is not capable of create a stub for an interface. (Type 'SinonStubbedInstance<Response>' is missing the following properties from type 'Response<any, Record<string, any>>': sendStatus, links, send, jsonp, and 77 more.)
Long story short: Any ideas how to unit-test a controller with a injected response object?
Is this a good solution for this problem? What could be a better approach?
How to avoid authentication interceptors getting invoked for requests beling forwarded
Do we need to do any additional to avoid CORS issues as cors is the first middleware called in the sequence
app.use('/authentication', checkAuthentication)
app.use ('/authorization', checkAuthrorization)
app.use('/protectedResource', protectedResourceController)
Request GET /v1/characters failed with status code 500. Error: Invalid type for property Armor
at Function.ModelClass.registerProperty (S:\dev\runes-law\player-api\node_modules\loopback-datasource-juggler\lib\model-builder.js:557:13)
at ModelBuilder.defineClass [as define] (S:\dev\runes-law\player-api\node_modules\loopback-datasource-juggler\lib\model-builder.js:642:16)
at SageMongoDataSource.defineClass (S:\dev\runes-law\player-api\node_modules\loopback-datasource-juggler\lib\datasource.js:837:40)
at CharacterRepository.definePersistedModel (S:\dev\runes-law\player-api\node_modules\@loopback\repository\src\repositories\legacy-juggler-bridge.ts:205:35)
at CharacterRepository.ensurePersistedModel (S:\dev\runes-law\player-api\node_modules\@loopback\repository\src\repositories\legacy-juggler-bridge.ts:165:17)
at CharacterRepository.resolvePropertyType (S:\dev\runes-law\player-api\node_modules\@loopback\repository\src\repositories\legacy-juggler-bridge.ts:224:14)
at S:\dev\runes-law\player-api\node_modules\@loopback\repository\src\repositories\legacy-juggler-bridge.ts:200:22
at Array.forEach (<anonymous>)
at CharacterRepository.definePersistedModel (S:\dev\runes-law\player-api\node_modules\@loopback\repository\src\repositories\legacy-juggler-bridge.ts:190:43)
at CharacterRepository.ensurePersistedModel (S:\dev\runes-law\player-api\node_modules\@loopback\repository\src\repositories\legacy-juggler-bridge.ts:165:17)
at new DefaultCrudRepository (S:\dev\runes-law\player-api\node_modules\@loopback\repository\src\repositories\legacy-juggler-bridge.ts:144:28)
at new CharacterRepository (S:\dev\runes-law\player-api\src\repositories\character.repository.ts:14:5)
at S:\dev\runes-law\player-api\node_modules\@loopback\context\src\resolver.ts:76:14
at Object.transformValueOrPromise (S:\dev\runes-law\player-api\node_modules\@loopback\context\src\value-promise.ts:298:12)
at Object.instantiateClass (S:\dev\runes-law\player-api\node_modules\@loopback\context\src\resolver.ts:69:35)
at S:\dev\runes-law\player-api\node_modules\@loopback\context\src\binding.ts:883:21
Hi @manchuwook, Slack is the recommended platform.
Here’s a copy of my previous message above:
—-
Hi everyone, gentle reminder that Slack is the recommended platform for the community and Gitter is not actively monitored by the maintainers. A link can be found on https://loopback.io navbar and strongloop/loopback-next#5048.
Hi, I have created a model and trying to cast/validate the post req body. But, loopback is ignoring the model definition.
Model Definition :
import {Entity, model, property} from '@loopback/repository';
import {company, customer} from '../interfaces';
@model()
export class BulkCompany extends Entity {
@property({
type: 'number',
id: true,
generated: true,
})
id?: number;
@property({
type: 'object',
required: true,
})
company: company;
@property({
type: 'object',
required: true,
})
customer: customer;
constructor(data?: Partial<BulkCompany>) {
super(data);
}
}
export interface BulkCompanyRelations {
// describe navigational properties here
}
export type BulkCompanyWithRelations = BulkCompany & BulkCompanyRelations;
Interfaces :
export interface beneficialOwners {
name: string;
title: string;
ownershipPercentage: number;
}
export interface company {
name: string;
state: string;
type: string;
designator: string;
website: string;
description: string;
industry: string;
beneficialOwners: beneficialOwners[];
alternateName: string;
}
export interface customer {
email: string;
name: string;
phone: string;
addressLine1: string;
addressCity: string;
addressState: string;
addressZip: string;
}
Route :
async createBulkCompanies(
@requestBody({
content: {
'application/json': {
schema: {
type: 'array',
additionalProperties: false,
items: getModelSchemaRef(BulkCompany, {
title: 'BulkCompany',
exclude: ['id'],
}),
},
},
},
})
company: [Omit<BulkCompany, 'id'>],
): Promise<any> {}
Problem is i am not getting a validation on company.beneficialOwners
Hi @mightytyphoon, Slack is the recommended platform.
Here’s a copy of my previous message above:
—-
Hi everyone, gentle reminder that Slack is the recommended platform for the community and Gitter is not actively monitored by the maintainers. A link can be found on https://loopback.io navbar and strongloop/loopback-next#5048.