How to enable CORS in Mulesoft on application level? - anypoint-studio

I need to enable CORS in Mulesoft on the application level. I already have found some solutions by setting CORS on the listener, but it doesn't work for me. Here is my HTTP listener configuration:
<http:listener-config name="erp-apoteka-api-httpListenerConfig">
<http:listener-connection host="0.0.0.0" port="8081" protocol="HTTPS"/>
<http:listener-interceptors>
<http:cors-interceptor>
<http:origins>
<http:origin url="http://localhost:3000" accessControlMaxAge="30000">
<http:allowed-methods>
<http:method methodName="GET" />
<http:method methodName="POST" />
<http:method methodName="DELETE" />
<http:method methodName="OPTIONS" />
<http:method methodName="PUT" />
</http:allowed-methods>
<http:allowed-headers >
<http:header headerName="Content-Type" />
<http:header headerName="Access-Control-Allow-Headers" />
<http:header headerName="Access-Control-Allow-Origin" />
</http:allowed-headers>
<http:expose-headers />
</http:origin>
</http:origins>
</http:cors-interceptor>
</http:listener-interceptors>
</http:listener-config>
I'm using React and Axios on frontend and when I do some calls, I got this error:
Access to XMLHttpRequest at 'http://localhost:8081/api/kategorije' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
KategorijeContainer.tsx:53 Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:83)
xhr.js:178 GET http://localhost:8081/api/kategorije net::ERR_FAILED
My axios settings are this:
export const axiosInstance = axios.create({
baseURL: BaseRoutes.ApiUrl,
headers: {
'Content-Type': 'application/json',
},
responseType: 'json',
});

Your http:listener-connection protocol is set to HTTPS but your origin is coming from http://localhost.. I'm assuming you're still in your development phase and have no TLS enabled on your mule backend, try changing it to HTTP.

Related

Deep linking issue when the app is open in background react native

I am facing an issue related to deep linking in react native. Deep linking is implemented for both ios and android. I am using deep linking to confirm user's account. User click on confirm my account on email sent to him which should ideally redirect him back to the application. Upon clicking the confirmation link, it does redirect it to the app.
If the app is closed, everything works fine and the user gets confirmed. But the issue is that if the app is already open, upon redirecting, it does not confirm the user.
This is my code that I have written in main entry file (App.js)
useEffect(() => {
Linking.getInitialURL().then(url => {
if (url == null) {
return;
} else {
handleDeepLink(url);
}
});
let subcribtion = Linking.addEventListener('url', handleDeepLink);
subcribtion.subscriber;
return () => {
subcribtion.remove();
};
}, []);
Here is my implementation in AndroidManifest.xml
<intent-filter >
<data android:scheme="com.sensights" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter >
<intent-filter android:autoVerify="true" android:label="stage01.random.ai">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="stage01.random.ai"
android:pathPrefix="/"
/>
<data android:scheme="https" android:host="stage01.random.ai"
android:pathPrefix="/"
/>
</intent-filter>
I also tried using App State from react native. But the issue with it is when comes on the foreground, Linking.getInitialURL() returns null.
My react native version is 0.70.5, react-navigation version is 4.4.4 and I am using universal links as deep linking approach.
Any help would be appreciated. Thanks in advance.
I was trying to confirm user account via deep linking but was unable to confirm user when the app was in background

Re render Header in ReactJs

I have index.js as below code:
<relevant imports>
function Header(){
return(<HeaderComponent/>);
}
ReactDOM.render(
<div>
<Router>
<div>
<Switch>
<Route path="/page1" component={page1} />
<Route path="/page2" component={page2} />
<Route path="/page3" component={page3} />
<Route path="/home" component={PortfolioPageComponent} />
<Route path="/" component={WelcomePage} />
</Switch>
</div>
</Router>
</div>,
document.getElementById('root')
);
ReactDOM.render(<Header />, document.getElementById('page-header'));
now when I am opening my app it goes to WelcomePage .In this component I have authorization logic. once Authetication is done, Page is redirecting to PortfolioPageComponent but header component is NOT getting reloaded.
How can I re-render Header component also on each redirection?
Putting the header component OUTSIDE the switch component allows it to render with each route. This way, no matter which route you navigate to, the components outside of the switch will always be rendered. This could be including a header before the switch component and a footer afterwards.

Routing from outside of a Route component

I have an app where i'm using react router and I can't figure out how to change the route in this use case. Here's how my code is structured:
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
<Router>
<Panels />
<Route path="/view" render={()=> <MyComponent />} />
<Route path="/about" render={()=> <MyOtherComponent />} />
</Router>
Inside <Panels> are some tabs I have that I would like to change the route.
<Tabs defaultActiveKey="1" onChange={}>
<TabPane tab="Tab 1" key="1" >
<Somecomponent />
</TabPane>
<TabPane tab="Tab 2" key="2">
Test me
</TabPane>
</Tabs>
These are antd tabs so they don't have a clickable component that I can put a <Link> into, and <Panels> is outside of a <Route> so I'm not sure if I'm able to access history object otherwise. I could put the panels in each <Route> but that would be really bad.
What way should I go about this?
Figured this one out finally.
import { withRouter } from 'react-router-dom'
...
<Tabs defaultActiveKey="1" onChange={(key)=> this.props.history.push(`/${key}`)}>
<TabPane tab="Tab 1" key="1" >
<Somecomponent />
</TabPane>
<TabPane tab="Tab 2" key="2">
Test me
</TabPane>
</Tabs>
...
export default withRouter(Panels);
wrapping the export with withRouter give the component access to the history object to push and read routes. I saw this solution initially but couldn't get it to work. Turns out it was because I was importing withRouter from react-router and not react-router-dom, so I was loading in the wrong history.

React-Router nested routes names

I would like to implement that kind of routes in react-router v4.
/auth => auth home page
/auth/login => login page
/auth/register => register page
/auth/forgot => lost password page
/auth/reset => change password page
It doesn't work with <Switch> because it first match /auth and render the associated component. So as I click on the link to go to the login page for instance it renders the Auth Component and not the Login Component.
How can I implement that behavior with react-router ?
I tried nested routing but if I take the same example as before, It would renders the Auth Component + Login Component.
Thanks.
You can add the exact prop to your /auth route:
<Switch>
<Route exact path='/auth' component={Auth} />
<Route path='/auth/login' component={Login} />
<Route path='/auth/register' component={Register} />
<Route path='/auth/forgot' component={ForgotPassword} />
<Route path='/auth/reset' component={ChangePassword} />
</Switch>
Alternatively, you could move your /auth route to the end of the list so other routes match first:
<Switch>
<Route path='/auth/login' component={Login} />
<Route path='/auth/register' component={Register} />
<Route path='/auth/forgot' component={ForgotPassword} />
<Route path='/auth/reset' component={ChangePassword} />
<Route path='/auth' component={Auth} />
</Switch>
I hope this helps.

Vbulletin Custom BBcode, Flowplayer and RTMP

I'm trying to embed flowplayer in my clients vbulletin forum and have succeeded with basic videos in the s3 bucket but am having trouble trying to implement rtmp. I've set up the distribution ok and can stream to a plain html page outside of vbulletin but am hitting a wall trying to write a custom bbcode to embed in posts.
My code for basic embed looks like this in my cusotom bbcode...
<object id="flowplayer" width="624" height="352" data="http://www.MY_DOMAIN.com/forums /flowplayer/flowplayer-3.2.14.swf" type="application/x-shockwave-flash">
<param name="movie" value="http://www.MY_DOMAIN.com/forums/flowplayer/flowplayer-3.2.14.swf" />
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="quality" value="autohigh" />
<param name="flashvars" value='config={"clip":{"autoPlay":false,"accelerated":true,"url":"{param}"}}' />
</object>
And my working rmtp streaming looks like this...
<HTML>
<HEAD>
<TITLE>
Streaming Video with Flowplayer
</TITLE>
</HEAD>
<BODY>
<H1>HSL501 Observation Video</H1>
<script type="text/javascript" src="http://www.MY_DOMAIN.com/forums/flowplayer/flowplayer-3.2.11.min.js"></script>
<div id="page">
<div id="rtmpPlayer" style="display:block;width:1000px;height:500px;"></div>
<script language="javascript">
// our custom configuration is given in third argument
flowplayer("rtmpPlayer", "http://www.MY_DOMAIN.com/forums/flowplayer/flowplayer-3.2.14.swf",{
plugins: {
rtmp: {
url: 'http://www.MY_DOMAIN.com/forums/flowplayer/flowplayer.rtmp-3.2.11.swf',
netConnectionUrl: 'rtmp://XXXX.cloudfront.net/cfx/st'
}
},
clip: {
url: 'mp4:entries%207.mp4'',
provider: 'rtmp'
}
});
</script>
</div>
</html>
Any help would be much appreciated
Steve
Finally figured it out and hopefully this will help somebody else and save them having to search for hours like I did.
<object width="656" height="420" data="http://www.MY_DOMAIN.com/forums/flowplayer/flowplayer-3.2.14.swf" type="application/x-shockwave-flash">
<param name="movie" value="http://www.MY_DOMAIN.com/forums/flowplayer/flowplayer-3.2.14.swf" />
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" /><param name="flashvars" value='config={"clip":{"url":"mp4:{param}","bufferLength":1,"provider":"dtfl"},"plugins":{"dtfl":{"url":"http://www.MY_DOMAIN.com/forums/flowplayer/flowplayer.rtmp-3.2.11.swf","netConnectionUrl":"rtmp://XXXXX.cloudfront.net/cfx/st"},"controls":{"backgroundGradient":[0.1,0.3,0,0,0],"bufferGradient":"none","sliderColor":"#272727","backgroundColor":"#000","sliderGradient":"small","buttonOverColor":"#272727","borderRadius":"0px","buttonColor":"#565656","timeColor":"#CCCCCC","progressColor":"#565656","durationColor":"#ffffff","bufferColor":"#CCCCCC","progressGradient":"medium","opacity":1}}}' />
</object>
Steve, in Clip --> url , you are giving My_Domain, whereas it should be URI of your file present in S3. Let me know exactly what is happening when you load the page and play video, as we also faced issues in making it work , but finally did it after few fixes.