Integrating Pusher with Laravel and Ionic 1( AngularJS) in chat app - angularjs

I'm trying to set up a chat application with the following stack (Laravel, AngularJS, Ionic, Pusher)
I'm using AngularJS v1.6.x and Laravel 5.3 (which has already Pusher integrated with it per default)
So I followed the docs to create a pusher account, and set up an Event in laravel with broadcasting and everything, and in the front-end (Ionic side) I have to add Pusher, which made me a bit confused since in pretty much all the tutorials they mentioned using Laravel Echo or Redis/Socket.IO
So my question how can I make this architecture work from the AngularJS side, do I only need to include the Pusher javascript file and declare the channel and work or is there something else I can do.
Cheers.

Yes. if using Pusher you don't need include in to project other tools. Such as Socket.io, redis or any other comet servers.

I figured it out! for anyone out there who has problems setting up Pusher with Laravel, here are the steps to follow:
Add Pusher to laravel using composer (composer require
pusher/pusher-php-server)
Inside your .env file add:
PUSHER_APP_ID=YOUR_APP_ID PUSHER_KEY=YOUR_APP_KEY
PUSHER_SECRET=YOUR_APP_SECRET
Set the broadcast driver to pusher:
BROADCAST_DRIVER=pusher
Inside config/Broadcasting.php
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'eu',
'encrypted' => true
],
],
create an event that gonna be broadcastable

Related

Firebase - How to create proxy for web app to prevent CORS

I have a React app that pulling data via Rest API from a different domain.
In my development env in order to work around this, I am using http-proxy-middleware.
module.exports = function (app) {
app.use(
createProxyMiddleware("/shabbat", {
target: "https://www.hebcal.com",
changeOrigin: true
})
)
}
Since I am using Firebase to host my web app I need to handle this via Firebase but can't figure it our how to properly configure.
I would appreciate it if someone can share a working example.
Thank you
i also got this error, i changed to use another https://xxx api to test,then worked well, so i guess this issue is due to firebase's settings, but i haven't found the solution

Stage management with AWS Mobile hub and AWS Amplify

I am currently writing a web app and am using AWS Amplify.
I created my API Gateway and my lambdas before using Amplify so I imported my existing API to Mobile Hub.
My API gateway has 2 stages dev and prod.
According to the Amplify documentation here is the code to call my API from my app.
API.get(apiName, path, myInit).then(response => {
// Add your code here
}).catch(error => {
console.log(error.response)
});
apiName is auto generated by Mobile Hub and is always ...amazonaws.com/dev
path will be /items for example
resulting in a call being made to ...amazonaws.com/dev/items
I haven't seen anything in Amplify or AWS documentation to be able to call ...amazonaws.com/prod/items using the Amplify library.
I tried to edit the mobile-hub-project.yml and change it from :
features:
cloudlogic: !com.amazonaws.mobilehub.v0.CloudLogic
components:
apiName: !com.amazonaws.mobilehub.v0.API
attributes:
...
sdk-generation-stage-name: dev
to :
features:
cloudlogic: !com.amazonaws.mobilehub.v0.CloudLogic
components:
apiName: !com.amazonaws.mobilehub.v0.API
attributes:
...
sdk-generation-stage-name: prod
and push the new configuration but the behaviour is still the same.
Could anyone help me to manage multiple stages using Amplify ?
can you check the file aws-exports.js on aws_cloud_logic_custom array. there each endpoint has an attribute called name which is the one you use with the Amplify. You can edit the endpoint by changing to the stage you want to use. By default aws-exportsuses dev stage.

cakephp3 load plugin for special prefix

I have Cakephp 3 application and i want to load this plugin and the event listener below it just for admin prefix. ( not the entire project ) .
how can i achive this?
this is my
config/bootstrap.php
where i load this plugin . (I load these at end of the file )
...
Plugin::load('Josegonzalez/Upload');
\Cake\Event\EventManager::instance()->on(new \App\Controller\Event\AppEventListener());
i want these to line only run on admin prefix
You can't conditionally run code based upon routing inside boostrap.php as the routing configuration for you app hasn't been loaded yet.
You'll have to do it old school style and use $_SERVER['REQUEST_URI'].
$url = $_SERVER['REQUEST_URI'];
$admin = '/admin/';
if(substr($url, 0, strlen($admin)) === $admin) {
Plugin::load('Josegonzalez/Upload');
\Cake\Event\EventManager::instance()->on(new \App\Controller\Event\AppEventListener());
}
Updated
Your plugin should have it's own bootstrap file. Which contains
Upload/config/bootstrap.php:
\Cake\Event\EventManager::instance()->on(new \App\Controller\Event\AppEventListener());
The app's bootstrap then tells CakePHP to include the bootstrap when loading the plugin.
App/config/bootstrap.php:
Plugin::load('Josegonzalez/Upload', ['bootstrap' => true]);
You shouldn't conditionally load your plugin.
I think you are searching for authentication on requests to your plugin. You want to limit use of your plugin only to authorized administrators. That is not a plugin issue. It is an authentication issue and you should be using the Authentication component in your plugin to verify the request is valid, and that the current user is an administrator.
Quoting cakephp plugin docs https://book.cakephp.org/3.0/en/plugins.html#plugin-routes
You can also load plugin routes in your application’s routes list. Doing this provides you more control on how plugin routes are loaded and allows you to wrap plugin routes in additional scopes or prefixes.
So you can do
Router::scope('/', function ($routes) {
// Connect other routes.
$routes->scope('/admin', function ($routes) {
$routes->loadPlugin('Josegonzalez/Upload');
});
});
For your event listener, load it inside plugin bootstrap configuration
// inside plugin bootstra.php
\Cake\Event\EventManager::instance()->on(new
\App\Controller\Event\AppEventListener());

rails angular js subdomain

I am new to angular js and I want request the server which is already implemented with subdomain for api part . I am facing issues when I want request the server api part from angular js . I tried like the following
1st case:
#service = $resource('/api.lvh.me/properties/:property_id/rates/:id',{})
2nd case:
#service = $resource('/api.lvh.me/properties/:property_id/rates/:id.json',{})
3rd case:
#service = $resource('http://api.lvh.me:3000/properties/:property_id/rates/:id.json',{})
no one is working for me , but when I tried the following its working fine
#service = $resource('/properties/:property_id/rates/:id.json',{})
In this case its hitting the normal controllers(not the api part/controllers) and I had to manage json type requests and rendering data accordingly , but I dont recommend this as I have already built the api part with sub domain constraint in rails , I want to go with this .
my routes defined like the following
namespace :api, defaults: {format: 'json'} , :path => '' , :constraints => {:subdomain => 'api'} do
....
end
Can anyone please help how to request the api part on the server .
Thanks ,
finally I fixed it by using rack-cors gem , I configured middileware as they suggested in application.rb file and changed my routing way like the following
$resource('http://api.lvh.me:3000/properties/:property_id/rates/:id',{})
Hope it helps for someone.

Cakephp - Custom authentification (basicauth) in a plugin

I am currently developing an Restfull API for my website.
I decided to develop it as a plugin.
I am using a custom class that extends BasicAuthentification. It allows me to check the client-app credential, in order to limit the API use to only approved developers.
This file works perfectly when added in the CakePHP CORE : Cake/Controller/Component/Auth/DeviceAuthentification.php
Since I am developing a Plugin, I would like everything to be inside the same directory.
Therefore in my plugin directory called MyApi, I added my custom class in the following path :
MyApi/Controller/Auth/DeviceAuthentification.php
In order to load it, in my Plugin's controller MyApiAppController, I added the following code :
public $components = array(
'Auth' => array(
'authenticate' => 'Device', // I also tried MyApi.Device
'sessionKey' => false
)
);
It does not load, the error is the following :
Authentication adapter "Device" was not found.
Anybody has an idea ?
Well, after having a look in the core file AuthComponent, it seems that you need to have the following path :
MyApi/Controller/Component/Auth/DeviceAuthentification.php
instead of
MyApi/Controller/Auth/DeviceAuthentification.php
Therefore, whenever you are working in the Plugin directory, you need to add the directory Component

Resources