how could i receive xml through a remote method in loopback? - node.js

I'm trying to create a remote method that accepts XML, i define my remote method like this,
WechatModel.remoteMethod('notify', {
description: 'notify',
accepts: [
{
arg: 'response',
type: 'string',
required: true,
http: {
source: 'body',
},
},
],
http: {
verb: 'post',
path: '/notify',
},
});
then i changed my server/config.js like this:
"rest": {
"normalizeHttpPath": false,
"xml": true
},
but,i still got a string with the content "[object Object]"

Related

You don't have permission to access this resource. nuxt npm run generate

In nuxt project, when you refer to an address other than the main address, you will see this message.
(Keep in mind that this does not happen when you are in the app and move to other pages, and only happens when you directly enter the address in the url of the browser!
Can it be from standalone method?)
For example:
cpalizade.ir | is ok
cpalizade.ir/login | not ok(forbidden)
It should be noted that this happens in projects where we use
run generate
and upload dist file in public_html.
but it will not happen when we use
run build
my nuxt.config.js:
import colors from 'vuetify/es5/util/colors'
export default {
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
titleTemplate: 'Cp Alizade',
title: 'Cp Alizade',
meta: [{
charset: 'utf-8'
},
{name: "msapplication-TileColor", content: "#da532c"},
{name: "theme-color", content: "#ffffff"},
{
name: 'viewport',
content: 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'
},
{
name: 'apple-mobile-web-app-capable',
content: 'yes'
},
{
name: 'apple-mobile-web-app-status-bar-style',
content: 'default'
},
{
hid: 'description',
name: 'description',
content: ''
},
],
link: [
{rel: "apple-touch-icon", sizes: "180x180", href: "/apple-touch-icon.jpg"},
{rel: "icon", type: "image/png", sizes: "32x32", href: "/favicon.png"},
{rel: "icon", type: "image/png", sizes: "16x16", href: "/favicon.png"},
{rel: "manifest", href: "/site.webmanifest"},
{rel:"mask-icon", href: "/safari-pinned-tab.svg", color: "#5bbad5"},
],
},
// Global CSS (https://go.nuxtjs.dev/config-css)
css: [
'#/assets/css/main.scss',
'#mdi/font/css/materialdesignicons.min.css'
],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [
// {
// src: '#/plugins/swiper.js',
// mode: 'client'
// },
// {src: '~/plugins/chart.js', mode: 'client'},
{
src: '#/plugins/vuelidate.js'
},
{
src: '#/plugins/pouchdb.js',
mode: 'client'
},
],
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/vuetify
['#nuxtjs/vuetify', {
rtl: true,
iconfont: 'mdi'
}],
],
// Modules: https://go.nuxtjs.dev/config-modules
modules: [
// https://go.nuxtjs.dev/axios
'#nuxtjs/axios',
// https://go.nuxtjs.dev/pwa
'#nuxtjs/pwa',
'#nuxtjs/auth-next',
'nuxt-leaflet',
],
auth: {
redirect: {
login: '/login',
logout: '/login',
callback: '/login',
home: '/'
},
strategies: {
local: {
scheme: 'local',
token: {
property: 'access_token',
required: true,
type: 'Bearer'
},
user: {
property: false, // <--- Default "user"
autoFetch: true
},
endpoints: {
login: {
url: 'https://api.cpalizade.ir/api/' + 'users/login',
method: 'post'
},
logout: {
url: 'https://api.cpalizade.ir/api/' + 'users/logout',
method: 'post'
},
user: {
url: 'https://api.cpalizade.ir/api/' + 'user',
method: 'get'
}
}
},
phone: {
scheme: 'local',
token: {
property: 'access_token',
required: true,
type: 'Bearer'
},
user: {
property: false, // <--- Default "user"
autoFetch: true
},
endpoints: {
login: {
url: 'https://api.cpalizade.ir/api/' + 'users/login-w-otp',
method: 'post'
},
logout: {
url: 'https://api.cpalizade.ir/api/' + 'users/logout',
method: 'post'
},
user: {
url: 'https://api.cpalizade.ir/api/' + 'user',
method: 'get'
}
}
}
}
},
// Axios module configuration: https://go.nuxtjs.dev/config-axios
axios: {
// See https://github.com/nuxt-community/axios-module#options
baseURL: 'https://api.cpalizade.ir/api/',
credentials: false,
proxy: false,
debug: true,
retry: {
retries: 0
},
requestInterceptor: (config, {
store
}) => {
config.headers.common['Content-Type'] = 'application/x-www-form-urlencoded;application/json';
config.headers.common['Access-Control-Allow-Origin'] = '*';
return config
}
},
// PWA module configuration: https://go.nuxtjs.dev/pwa
pwa: {
manifest: {
name: 'Cp Alizade',
short_name: 'Cp Alizade',
lang: 'fa',
theme_color: '#222',
background_color: '#222',
start_url: `/`,
prefer_related_applications: true,
},
icon: {
fileName: 'favicon.png'
},
},
// Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify
vuetify: {
customVariables: ['~/assets/variables.scss'],
defaultAssets: false,
theme: {
dark: false,
themes: {
light: {
primary: '#1938d3',
secondary: '#ff2626',
info:'#1867c0',
jozi: '#45c235'
},
dark: {
primary: '#1938d3',
accent: colors.grey.darken3,
secondary: colors.amber.darken3,
info: colors.teal.lighten1,
warning: colors.amber.base,
error: '#DF382C',
success: colors.green.accent3
}
}
}
},
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
extend(config, ctx) {
} // blah blah
}
}
.htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
DirectoryIndex 200.html
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /200.html [L]

Change an array loaded from another component in React.js jsx

I am trying to change a hardcoded array within another JSX file.
the first file routes.js. I tried loading the array then changing it . it just changes the loaded data not the array directly from the other file. How do i write to the other JSX array from the main component.
const routes = [
{
type: "collapse",
name: "Our Mission",
key: "dashboards",
icon: <Shop size="12px" />,
collapse: [
{
name: "Ways We can Help",
key: "default",
route: "/dashboards/default",
component: Default,
},
{
name: "How It Works",
key: "automotive",
route: "/dashboards/automotive",
component: Automotive,
},
{
name: "Who We Are",
key: "smart-home",
route: "/dashboards/smart-home",
component: SmartHome,
},
],
},
{ type: "title", title: " ", key: "space1" },
{
type: "collapse",
name: "Services",
key: "services",
icon: <Shop size="12px" />,
href: "https://github.com/creativetimofficial/ct-soft-ui-dashboard-pro-material-ui/blob/main/CHANGELOG.md",
component: Default,
noCollapse: true,
},
{
type: "collapse",
name: "Products",
key: "products",
icon: <Shop size="12px" />,
href: "https://github.com/creativetimofficial/ct-soft-ui-dashboard-pro-material-ui/blob/main/CHANGELOG.md",
component: Default,
noCollapse: true,
},
];
export default routes;
code used in main jsx file. I want to be able to write to the remote array changing its values.
const handleSubmit = (event) => {
event.preventDefault();
// I want to push or filter with the code below
{
routes.length = 0;
routes.map((route) => console.log({ route }));
}
};
You can't change the array itself because it's a const. You could change it to a let and then export it like this:
EDIT
export let routes = [
{
type: "collapse",
name: "Our Mission",
key: "dashboards",
icon: <Shop size="12px" />,
collapse: [
{
name: "Ways We can Help",
key: "default",
route: "/dashboards/default",
component: Default,
},
{
name: "How It Works",
key: "automotive",
route: "/dashboards/automotive",
component: Automotive,
},
{
name: "Who We Are",
key: "smart-home",
route: "/dashboards/smart-home",
component: SmartHome,
},
],
},
{ type: "title", title: " ", key: "space1" },
{
type: "collapse",
name: "Services",
key: "services",
icon: <Shop size="12px" />,
href: "https://github.com/creativetimofficial/ct-soft-ui-dashboard-pro-material-ui/blob/main/CHANGELOG.md",
component: Default,
noCollapse: true,
},
{
type: "collapse",
name: "Products",
key: "products",
icon: <Shop size="12px" />,
href: "https://github.com/creativetimofficial/ct-soft-ui-dashboard-pro-material-ui/blob/main/CHANGELOG.md",
component: Default,
noCollapse: true,
},
];
Then to use it in another jsx component you can import it like this.
import {routes} from '../yourPathToIt/main'

Setup #semantic-release for considering 'refactor' commits in the CHANGELOG

Using #semantic-release I'd like to consider refactor changes for both, triggering a new release and write down in the CHANGELOG.md file.
So far, I've included refactor commits at "#semantic-release/commit-analyzer" so they are triggering a patch release:
[
"#semantic-release/commit-analyzer",
{
"preset": "angular",
"releaseRules": [
{
"type": "refactor",
"release": "patch"
}
]
}
],
But those commit msgs aren't included in the CHANGELOG file, how can I setup "#semantic-release/release-notes-generator" plugin for including refactor commits? I find related doc confusing and lack of examples
generated CHANGELOG example
## [0.6.4](.../compare/v0.6.3...v0.6.4) (date)
## [0.6.3](.../compare/v0.6.2...v0.6.3) (date)
desired CHANGELOG
## [0.6.4](.../compare/v0.6.3...v0.6.4) (date)
[[>>INCLUDE HERE COMMIT MSG + LINK<<]]
## [0.6.3](.../compare/v0.6.2...v0.6.3) (date)
If anyone finds this useful: we need to config "#semantic-release/release-notes-generator" for considering other keywords besides feat and fix including these dicts:
{
"type": "refactor",
"section": "title to be used in changelog.md",
"hidden": false
}
For copy-pasting, this setup is gathering both refactor, chore and perf into ## Internal section (note i needed to write explicitly default values, I guess this is because it's overriding the config)
[
"#semantic-release/release-notes-generator",
{
"preset": "conventionalCommits",
"parserOpts": {
"noteKeywords": [
"BREAKING CHANGE",
"BREAKING CHANGES",
"BREAKING"
]
},
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"section": "Internal",
"hidden": false
},
{
"type": "refactor",
"section": "Internal",
"hidden": false
},
{
"type": "perf",
"section": "Internal",
"hidden": false
}
]
}
}
]
The above answer is correct, but I feel its a bit incomplete. Even after adding the above commit types, the release will not be triggered on all the commit types. If you wish to trigger the release on all or selected commit types (ex. refactor, docs ci etc.) you can use the configuration as below:
// release.config.js
module.exports = {
plugins: [
[
'#semantic-release/commit-analyzer',
{
preset: 'conventionalCommits',
releaseRules: [
{ type: 'revert', scope: '*', release: 'patch' },
{ type: 'docs', scope: '*', release: 'patch' },
{ type: 'style', scope: '*', release: 'patch' },
{ type: 'chore', scope: '*', release: 'patch' },
{ type: 'refactor', scope: '*', release: 'patch' },
{ type: 'test', scope: '*', release: 'patch' },
{ type: 'build', scope: '*', release: 'patch' },
{ type: 'ci', scope: '*', release: 'patch' },
{ type: 'improvement', scope: '*', release: 'patch' },
],
},
],
[
'#semantic-release/release-notes-generator',
{
preset: 'conventionalCommits',
presetConfig: {
types: [
{ type: 'feat', section: 'Features' },
{ type: 'fix', section: 'Bug Fixes' },
{ type: 'perf', section: 'Performance Improvements' },
{ type: 'revert', section: 'Reverts' },
{ type: 'docs', section: 'Documentation', hidden: false },
{ type: 'style', section: 'Styles', hidden: false },
{ type: 'chore', section: 'Miscellaneous Chores', hidden: false },
{ type: 'refactor', section: 'Code Refactors', hidden: false },
{ type: 'test', section: 'Tests', hidden: false },
{ type: 'build', section: 'Build System', hidden: false },
{ type: 'ci', section: 'CI/CD', hidden: false },
{ type: 'improvement', section: 'Improvements', hidden: false },
],
},
},
],
['#semantic-release/github'],
[
'#semantic-release/npm',
{
npmPublish: false,
},
],
'#semantic-release/changelog',
'#semantic-release/git',
],
branch: 'master',
};
Working of the above config:
#semantic-release/commit-analyzer will trigger the release for feat, fix & BREAKING CHANGE as usual. I've only added the rest of the types that are ignored by default. Needless to say that they will be considered as patches and will only bump the patch number from semantic versioning in your tags, release notes, changelog & package.json file.
#semantic-release/release-notes-generator will just make sure that the commits are grouped correctly based on the type and will display my custom headings defined with the section key.
Hope this helps someone in future!

putMapping illegal_argument_exception without message

I try to call putMapping from elasticsearch javascript client, but always got an error with status code 400, illegal_argument_exception.
When I call getMapping for "documents" index I got:
{
"documents":{
"mappings": {
"properties":{
"category":{"type":"text","fields":{"keyword":
{"type":"keyword","ignore_above":256}}},
"createdAt":{"type":"text","fields":{"keyword":
{"type":"keyword","ignore_above":256}}},
"id":{"type":"text","fields":{"keyword":
{"type":"keyword","ignore_above":256}}},
"info":{"type":"text","fields":{"keyword":
{"type":"keyword","ignore_above":256}}},
"text":{"type":"text","fields":{"keyword":
{"type":"keyword","ignore_above":256}}},
"title":{"type":"text","fields":{"keyword":
{"type":"keyword","ignore_above":256}}},
"visibility":{"type":"boolean"}
}
}
}
}
I tried to call putMapping with same properties and add a new parameter 'index': 'not_analyzed' to category field:
esClient.indices.putMapping({
index: 'documents',
type: 'document',
body: {
document: {
properties: {
title: { type: 'text' },
info: { type: 'text' },
text: { type: 'text' },
category: { type: 'text', index:
'not_analyzed'
},
visibility: { type: 'boolean' },
createdAt: { type: 'text' },
},
},
},
}, (err, resp) => {
if (err) {
console.error(err);
}
else {
console.log('Successfully Created Index', resp);
}
});
I got this error:
ResponseError: illegal_argument_exception
at IncomingMessage.<anonymous> (/Users/user/reference_sys_cfu-back/node_modules/#elastic/elasticsearch/lib/Transport.js:287:25)
at IncomingMessage.emit (events.js:208:15)
at IncomingMessage.EventEmitter.emit (domain.js:476:20)
at endReadableNT (_stream_readable.js:1168:12)
at processTicksAndRejections (internal/process/task_queues.js:77:11) {
name: 'ResponseError',
meta: {
body: { error: [Object], status: 400 },
statusCode: 400,
headers: {
'content-type': 'application/json; charset=UTF-8',
'content-length': '345'
},
warnings: null,
meta: {
context: null,
request: [Object],
name: 'elasticsearch-js',
connection: [Object],
attempts: 0,
aborted: false
}
}
}
index: 'not_analyzed' - I do this for use "term" method for exact finding strings, but it (index: 'not_analyzed') deprecated in 2.x version of elasticsearch. Now I just use field.keyword: 'query string', to finding exact strings.

jqgrid - filter/search always gives me only "contains" operator for a option

I am using jQgrid - and it is great!
I have one problem.
(Oleg are you still around?)
In the search/filter form (were you can choose the coulmn you want to filter and the operation you want do to), the only things that comes up is the "contain" operator.
My colModel looks like this:
var columnModel = [{ name: 'ID', index: 'ID', sortable: true, searchoptions: { sopt: ['eq', 'cn','bw']}},
{ name: 'FirstName', index: 'FirstName', sortable: true},
{ name: 'LastName', index: 'LastName', sortable: true }
];
But it only gives me the contains operator.
The full grid is like this:
myGrid.jqGrid({
url: './ViewNQueryData.asmx/ViewNQueryData',
datatype: 'json',
mtype: 'POST',
postData: {userID:currentUserId, sphereID:currentSphereId},
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (postData)
{
if (postData.filters === undefined) postData.filters = null;
return JSON.stringify(postData);
},
jsonReader: {
root: function (obj) { return obj.d.rows; },
page: function (obj) { return obj.d.page; },
total: function (obj) { return obj.d.total; },
records: function (obj) { return obj.d.records; }
},
colModel: columnModel,
colNames: columnNames,
rowNum: 10,
rowList: [10, 20, 300],
sortable: true,
pager: "#ViewNQueryPager",
viewrecords: true,
gridview: true,
height: 250,
shrinkToFit: true, //If using frozen coulmns change to false.
gridComplete: function ()
{
$('#totalRecordsFound').html(myGrid.jqGrid('getGridParam', 'records') + " Customers");
},
loadError: function ()
{
alert("Error fetching data");
}
}).jqGrid('navGrid', '#ViewNQueryPager',
{ edit: false, add: false, del: false, search: true, view: true }, //option
{}, // use default settings for edit
{}, // use default settings for add
{}, // delete instead that del:false we need this
{multipleSearch: true, multipleGroup: true, showQuery: true, onSearch: function (response) { showQueryDetails(); } },
{ height: 250, jqModal: false, closeOnEscape: true} // view options
);
Can any one help me with this???
Fixed!
I had a snippet of code on my page that was doing this....

Resources