Add listener from module in directus - directus

I want to create an extension for Directus (like a module), and I want to listen to an event.
But the script is only executed when the module is open.
How do I attach a listener when starting Directus?

Related

Using Workbox via a local copy, without a CDN

I have a small device that serves a webpage using Nginx in a local network. I'm developing the webpage using Vue and I need that once a person got connected to the server and visited the page, on disconnection, the page needs to work as normal
I'm currently using Workbox plugin and I get this code:
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
importScripts(
"/precache-manifest.b62cf508e2c3da8c27f2635f7aab384a.js"
);
The problem is that it goes to the internet to download that file and I will not have an internet connection.
I tried downloading this file, but inside goes to the internet again.
Is there a way to get this to work in an offline environment?
You can follow the guidance in the workbox-sw docs to download a local copy of the bundled Workbox runtime libraries, and modify your service worker script to use those.
Running:
$ npx workbox-cli#4.3.1 copyLibraries /path/to/dir
from the command line will download a local copy of the runtime to the specified directory (replace /path/to/dir with the desired location).
You can then modify your service worker script so that it reads:
importScripts("/path/to/dir/workbox-v4.3.1/workbox-sw.js");
workbox.setConfig({
modulePathPrefix: '/path/to/dir/workbox-v4.3.1/'
});
importScripts(
"/precache-manifest.b62cf508e2c3da8c27f2635f7aab384a.js"
);

Joomla external URL redirect on successful login

Im looking to override the default joomla login redirect and use an external url on succesful login (which currently doesn't seem possible within the default joomla setup).
I found this support doc:
https://docs.joomla.org/How_do_you_redirect_users_after_a_successful_login%3F
The code I would add would be as follows.. correct?
$redirectUrl = urlencode(base64_encode("http://subdomain.mydomain.com"));
$joomlaLoginUrl = 'index.php?option=com_users&view=login';
$finalUrl = $joomlaLoginUrl . $redirectUrl;
But im not sure where to add this code, in the support doc it says 'in your Administration back end from your custom code'?
Any help would be much appreciated.
The default login module of joomla loads menu item that are published in joomla. So you can create a new menu item using the type "System links -> external url" Put your external url in that menu item.
That menu item will now show up in the module administration. You just need to select it.
You could as well modify the php of the module. The module is called mod_login in the folder modules. You might also consider creating a new module. Download all the files, do your modifications, change the mod_login.xml, in order to change the name of the module, add your name as well etc. Zip the whole folder and then install it through the normal joomla installer. Like this you will not have upgrade issues.
The file to modify is called helper.php in mod_login folder. On line 45 you can edit:
return base64_encode($url);
And change it to:
return base64_encode("http://your.url.com");

Add a route in osx's routing table programmatically

In my app i want to add a specific route in OSX's routing table which i can easily add through the terminal like this
/sbin/route add -host X.X.X.X -interface en1
. for that i do some search on google and get to know that there is a file /etc/ppp/ip-up which consult by OS every time when a ppp link is up so i set my target to modify this file programmatically
but then OS not allow me without root access so now i have to make possible this command to run programmatically now i found on google "i have to run a helper tool with my app because it can be run as root user" and get SMJobBless API and run it's sample. It was successful
but now i have a question how i can add this route in routing table by this helper tool i mean if i use CreateAuthorization and use this command to run with this! it again prompt for root password which user already give at the time of installation of this app, which is very very annoying
as in this sample app
http://ideveloper.co/designing-writing-and-deploying-a-privileged-helper-on-mac-os-x/
now please tell me what i should do
The best place to look is the source code for Apple's pppd and route tools. Both should include code for adding routes.
http://www.opensource.apple.com/source/network_cmds/network_cmds-307.0.1

Is it possible to run more than one rabbitmq instance on one machine?

I want to build a RabbitMQ cluster in my dev machine (windows).
reason is that I would like to test and study it.
Is it possible to run more than one rabbitmq instance on one machine?
I am guessing I need to:
Change the listening port
Change the appdata folder (C:\Users\MyUser\AppData\Roaming)
Change the ui plugin port so I can view all instances.
Remove the service and run from cli
Has anyone tried it?
Is there a known guide?
This thread appears to detail what you need. From the thread responses (scroll down):
The following settings are necessary to separate the node runtimes
completely, while allowing them to share the installed code base.
RABBITMQ_CONFIG_FILE /etc/rabbitmq/rabbitmq
RABBITMQ_MNESIA_BASE /var/lib/rabbitmq/mnesia
RABBITMQ_LOG_BASE /var/log/rabbitmq
RABBITMQ_ENABLED_PLUGINS_FILE /etc/rabbitmq/enabled_plugins
Now the official RabbitMQ documentation contains a section "A Cluster on a Single Machine", which describes how to run multiple Rabbit nodes on a single machine.
See https://www.rabbitmq.com/clustering.html#single-machine
One approach that I took when testing out clustering on my dev machine was to fire up several VMs. I had several for Rabbit and one for HAProxy.
While you can, as per one of the other answers, run multiple instances on a single OS instance, the multiple VM approach allowed me to mimic the intended production environment more closely.
NB. I have chosen to interpret your 'one machine' as meaning a physical machine for the purpose of this answer. If your meaning was 'virtual' then I defer to the other answer posted against this question which details how to accomplish this.
You can run multiple RabbitMQ instances on 1 machine without clustering. You just need to change the ports and the node name in rabbitmq-defaults, rabbitmq-env and config files.
For Linux:
Make sure you have Erlang installed, then download the latest version for Generic Unix and extract it.
Go to rabbit installation folder(the folder you just extracted)/sbin -> open the rabbitmq-defaults file and change SYS_PREFIX=${RABBITMQ_HOME} to create the default folder somewhere else, you should set the path to the extracted folder, for ex. /home/YOUR-USERNAME/rabbit_server-msg(this is my extracted folder).
Change the node name. Open the rabbitmq-env file -> find NODENAME=rabbit#${HOSTNAME} and change the name rabbit (ex. rabbitMSG#${HOSTNAME}). In the same file locate and change DEFAULT_NODE_PORT, by default it’s set to 5672. The default clustering port is set by ${DEFAULT_NODE_PORT} + 20000. So if you set the default node port to 5673, the clustering port will be 25673.
Install the Management Plugin. Navigate to rabbitmq-server/sbin and run “./rabbitmq-plugins enable rabbitmq_management”
The AMQP and HTTP ports need to be chnaged in the config file. Copy the file rabbitmq.config.example and paste it in the rabbit_server-msg(again this is my extracted forlder)/etc(this is the default folder created by RabbitMQ from step 1)/rabbitmq folder, rename the file to just rabbitmq.config. If you can’t find the file rabbitmq.config.example in the rabbit folder create a file named rabbitmq.config and copy the code from their GitHub.
Open the config file and uncomment the following lines:
– {tcp_listeners, [5672]} and change the port number (It is recommended to set the same number as the DEFAULT_NODE_PORT in rabbitmq-env for example 5673).
– {listener, [{port, 12345} and change the port number (This is for the management plugin).
NOTE: Be careful with the commas and brackets. Remove the comma after {tcp_listeners, [5672]}. Also after {listener, [{port, 12345} close the brackets like so ]}. Otherwise when you try to run ./rabbitmq-server it will show errors (It will show you on which line in the config file you have an error so you can fix it).
Now start up the server and log in the manager. Check the Listening ports under Ports and contexts to see if you made the changes. Do this for the other servers and you will be able to run as many servers as you want on 1 machine all with different listening ports. To start the RabbitMQ server automatically when you log in use the Startup Application program.
For Windows:
Setting up RabbitMQ for Windows is preatty much the same as on Linux.
Make sure you have Erlang installed, then download the latest version for Windows and extract it.
Go to rabbit(the folder you just extracted)/sbin -> open the rabbitmq-defaults.bat file and change RABBITMQ_BASE to create the default folder somewhere else, you should set the path to the extracted folder, for ex. C:/rabbit_server-msg(this is my extracted folder).
Change the node name. Open the rabbitmq-env.bat file -> find RABBITMQ_NODENAME=rabbit#!HOSTNAME! and change the name rabbit (ex. rabbitMSG#!HOSTNAME!). In the same file locate and change RABBITMQ_NODE_PORT, by default it’s set to 5672. To change the default clustering port locate and change RABBITMQ_DIST_PORT, by default it’s set to 25672.
Install the Management Plugin. Navigate to rabbit-server/sbin and run “rabbitmq-plugins.bat enable rabbitmq_management”.
The AMQP and HTTP ports need to be chnaged in the config file. Create a file named rabbitmq.config and copy the code from their GitHub. Put the file in your installation folder/RabbitMQ (ex. my config is in C:/rabbit_server-msg/RabbitMQ). Also in the rabbitmq-defaults.bat file check CONFIG_FILE it should be set to CONFIG_FILE=!RABBITMQ_BASE!\rabbitmq.
Open the config file and uncomment the following lines:
– {tcp_listeners, [5672]} and change the port number (It is recommended to set the same number as the RABBITMQ_NODE_PORTin rabbitmq-env for example 5673).
– {listener, [{port, 12345} and change the port number (This is for the management plugin).
NOTE: Be careful with the commas and brackets. Remove the comma after {tcp_listeners, [5672]}. Also after {listener, [{port, 12345} close the brackets like so ]}. Otherwise when you try to run rabbitmq-server.bat it will show errors (It will show you on which line in the config file you have an error so you can fix it).
Now start up the server and log in the manager. Check the Listening ports under Ports and contexts to see if you made the changes. Do this for the other servers and you will be able to run as many servers as you want on 1 machine all with different listening ports.
Source: https://lazareski.com/multiple-rabbitmq-instances-on-1-machine/

change configuration of CherryPy base service without restart

I have CherryPy based web service which dishes out data from flat files based on GET request query's. The list of files that it uses as its database is specified in a yaml based configuration file.
Now each time I want to add/remove a file from that yaml config file, I have edit the yaml configuration file and then restart the service.
What would be the easiest way for me to implement a scheme, so that each time I modify the config file to the configuration file, the web service would automatically detect the change and reload the contents of that file without requiring a restart.
My goal is to avoid downtime completely and not interrupt my customers who are running the queries.
If your service is behind the apache using mod_rewrite:
create two instance of your application with different ports, and when *mod_rewrite* is configured to rewrite requests to instance A, you can change instance B config file, after auto-restart, you can change the apache config file, and issue:
/etc/init.d/apache reload
then change instance A's config file.
If your cherrypy is standalone you can use proxy server with mentioned two instance.