How to import a webpack bundle into service worker? - service-worker

I have been looking for a simple solution to importScript a full bundle created by webpack into a service worker. I have a few issues:
When I bundle a single file with webpack I can importScript this into my service worker. However, if I "require(import)" a file inside the file to be importScripted then the service worker complains that it does not know what export means. How do I fix this?
What format should my entry files be commonjs, umd...? Since importScript seems to just import the global functions of the file I don't even know if webpack is the right solution. Is it? Other people seems to have used it.
Can I import any node_module component I want just like on normal client side bundling? Are there limitations?
WHERE IS THE DOCUMENTATION??? Maybe I am misunderstanding something...
thanks in advance

That's not how service workers work.
importScripts is designed to import service worker code, not your application code.
What you really want is auto-generated service worker, based on your bundle. You can use this webpack plugin that uses excellent sw-precache under the hood.

Related

How do I set up a new ejabberd server?

I'm trying to figure out how to properly setup an ejabberd project that allows for easy compilation of custom beam files- so far, we've been using an existing project that is cumbersome to manage, and uses erlide as the IDE.
I would like to set up the project in a way that I can use a more helpful IDE like vscode, and somehow streamline the compiling and copying of the beam files and updating the module on the server.
Writing code in Elixir is fine as well- I just want the project to be set up in a way that is dev friendly.
Apologies if the question is too broad, but I'm not exactly sure how else to best phrase it. If you feel like I'm missing something in my current flow, please let me know, as I've basically inherited this project. If there are any clarifications required, let me know as well.
Thanks.
easy compilation of custom beam files
somehow streamline the compiling and copying of the beam files and updating the module on the server.
If the task is about compiling and loading additional modules, a running ejabberd node can compile, load and start additional modules in runtime, see
https://docs.ejabberd.im/developer/extending-ejabberd/modules/#ejabberd-contrib
Usually the modules come from
https://github.com/processone/ejabberd-contrib
but you can tell ejabberd to download other modules from other git repositories, or you can copy modules source code and tell ejabberd to install them. And those modules can be written in Erlang or Elixir. Full example: https://docs.ejabberd.im/developer/extending-ejabberd/elixir/#elixir-module-in-ejabberd-contrib
Basically:
you write the module in your development machine, test it...
when happy with the source code, copy mod_whatever.erl to the production machine, $HOME/.ejabberd-modules/sources/mod_whatever as explained in the example mentioned earlier
run ejabberdctl module_install mod_whatever
In step 2, instead of copying the source code yourself, you can have a git repository just for your module, tell ejabberd the module's git URL, similarly to https://github.com/processone/ejabberd-contrib/tree/master/extra
BTW, for step 3, starting in ejabberd 22.10, there's a page in ejabberd webadmin to install and uninstall those modules (copying the files requires manual administration of course).
I would like to set up the project in a way that I can use a more helpful IDE like vscode
What a coincidence, these days I'm playing with VSCode variants (VSCode, VSCodium, Coder's code-server and Github Codespaces) and how to develop ejabberd using them. This is useful for step 1 that I mentioned earlier (write module and test it). If you are interested in ejabberd + VSCode, tell me.

VueJS & Webpack: ENV var unaccessible from built project

I'm working on an app with vuejs frontend and nodejs backend. My frontend makes API https requests to the backend. I've started my projet with vue-cli and webpack.
I need to get the backend API url from env variable (BACKEND_URL).
Since i'm using webpack, I added this line to config/prod.env.js :
module.exports = {
NODE_ENV: '"production"',
-> BACKEND_URL: JSON.stringify(process.env.BACKEND_URL)
}
It works flawlessly in dev mode using webpack-dev-server. I pass the env var throught docker-compose file:
environment:
- BACKEND_URL=https://whatever:3000
But when I run build, I use nginx to serve the static files (but the problem is the same using visual studio code live server extension). I send BACKEND_URL env var the same way as before. The thing is now the process.env.BACKEND_URL is undefined in the app (but defined in the container)!! So I cant make backend http calls :(
I'm struggling finding the problem, please don't be rude with the responses. Thank you
They aren not "translated" during build time, this is what is happening with you. On a node environment, when you ask for process.env it will show all environment variables available in the system, that is true. But a web application does not have access to process.env when it is executing. You need a way to translate them during build time.
To achieve that you have to use DefinePlugin. It translates anything during build time and writes a magical string where this other thing was.
Using you own example:
module.exports = {
NODE_ENV: '"production"',
BACKEND_URL: JSON.stringify(process.env.BACKEND_URL)
}
If you do this during build time, without DefinePlugin, webpack won't know what to do with it, and it is going to be a simple string.
If you use DefinePlugin:
new webpack.DefinePlugin({
"process.env.BACKEND_URL": JSON.stringify(process.env.BACKEND_URL)
});
By doing this, you are allowing webpack to translate this during build time.
Give this a shot: https://www.brandonbarnett.io/blog/2018/05/accessing-environment-variables-from-a-webpack-bundle-in-a-docker-container/
If I'm understanding your problem correctly, you're serving a webpack bundle using nginx, and trying to access an environment variable from that bundle.
Unfortunately, it doesn't quite work that way. Your JS file has no access to the environment since it's a resource that has been delivered to the client. I've proposed a solution that also delivers those env variables alongside the bundle in a separate JS file that gets created on container start.
From VueJS Docs: https://cli.vuejs.org/guide/mode-and-env.html
Using Env Variables in Client-side Code
Only variables that start with VUE_APP_ will be statically embedded into the client bundle with webpack.DefinePlugin. You can access them in your application code:
console.log(process.env.VUE_APP_SECRET)
During build, process.env.VUE_APP_SECRET will be replaced by the corresponding value. In the case of VUE_APP_SECRET=secret, it will be replaced by "secret".
So in your case, the following should do the trick. I had the same problem once in my project, which I started with vue/cli and vue create project ...
VUE_APP_BACKEND_URL=https://whatever:3000

Sending cLog entries into a database from Talend Runtime

I'm configuring Talend ESB (OpenSource) and I want to be able to redirect the logging, such as from the Camel Log components etc., to a database.
I've tried editing the org.ops4j.pax.logging.cfg file to add a JDBCAppender, but when karaf imports this file I get a message "Unable to invoke factory method in class class org.apache.logging.log4j.core.appender.db.jdbc.JdbcAppender for element JDBC... No factory method found for class org.apache.logging.jog4j.core.appender.db.jdbc.JdbcAppender"
Is this likely to be because the right appender classes aren't registered in Karaf, in which case can someone point me where I can find the feature/bundle I need, or is there something more subtle going on that I am missing?
Thanks!
Note: this is to find your bundle and to install it in karaf
feature:list|grep -i camel
above command shows you which jdbc compenets aren't installed yet and you can install them in karaf using feature:install camel-jdbc try this.

Ember server only resolves files with the bower path used in the brocfile

In my ember cli app I have moment in both directories, but my ember server only works with the bower path, in my borcfile:
app.import("bower_components/moment/min/moment.min.js");
app.import("node_modules/moment/min/moment.min.js");
the latter says that it can't find it.
In order to reference node modules you ll need to import them by their name, the simplest example is: import Ember from 'ember'.
For more info regarding modules and the resolver refer to this part of the documentation

Has anyone succeeded in using celery with pylons

I have a pylons based webapp and i'd love to use celery + rabbitmq for some time taking tasks. I've taken a look at the celery-pylons project but I haven't succeeded in using it.
My main problem with celery is: where do i put the celeryconfig.py file or is there any other way to specify the celery options eg. BROKER_HOST and the like, from within a pylons app (In the same way one can put the options in the django settings.py file when using django-celery).
Basically, i investigated 2 options: using celery as a standalone project and using celery-pylons, both without much success.. :(
Thanks in advance for your help.
I am doing this currently, although I've not updated celery in some time. I'm still on 2.0.0 I think.
What I did was to create a celery_app directory within my pylons application. (so in same directory as data, controllers, etc.)
In that directory are my celeryconfig.py, tasks.py, and pylons_tasks.py.
pylons_tasks.py is just a file that initializes the pylons application so I can load Pylons models and such into the celery tasks.py file. So it does the pylons init and then imports tasks.py.
The celeryconfig is then set to use myapp.celery_app.pylons_tasks as the CELERY_IMPORTS value.
CELERY_IMPORTS = ("myapp.celery_app.pylons_tasks", )
Hope that helps some.
The tightest integration with pylons is to build a custom loader into paste commands. This is what celery-pylons does. Check out my fork of celery-pylons https://bitbucket.org/dougtabuchi/celery-pylons/src which should work with the latest celery and pylons 1.0.
To get the celeryd side working you need to add the correct options in your ini file and then call paster celeryd development.ini
For the webapp side you just need to import celerypylons in environment.py Then you will be able to import and use your tasks from anywhere in your project.
A good pylons project to look at that uses celery is https://rhodecode.org/rhodecode/files/tip/

Resources