Serve Local Web Application on Linux
This is record about how I manage local web-based application and wrap them with Electron. Why I choose Electron rather than just opening them in a browser is that separated applications provide more flexibility for WM.
Wrap a Web Service with Electron
nativefier is a tool to make any web page an electron application. However, local static files are not supported and hard to manage. So our goal is to host applications(static/server) in an organized way.
Host Static Files and Reverse Proxy
Of course I choose Nginx
as a (host/reverse proxy). The
server_name
is in the form of
{app_name.domain}
and will be the entry of our applications
used by nativefier
. How the server_name
is set
will be discussed in the next section.
Static Files
1 | server { |
Server
1 | server { |
Override Local DNS
Remembering ports for services is really painful, right? What we want
to do here is to resolve *.lan
locally and let
Nginx
handle request. Unfortunately /etc/hosts
doesn't support wildcard, so dnsmasq
is used to modify DNS
resolving.
Disable /etc/resolv.conf generation of NetworkManager
Add dns=none
to
/etc/NetworkManager/NetworkManager.conf
Setup DNS with dnsmasq
how to get dnsmasq private nameserver to work with networkmanager?
Install dnsmasq
and add edit /etc/dnsmasq.conf:
- set(uncomment)
no-resolv
to prevent reading /etc/resolv.conf - add
address=/loc/127.0.0.1
to point *.loc to localhost
(be careful that local
might be reserved so I use
loc
here)
- add
server=1.1.1.1
to provide DNSs for public domains
Restart dnsmasq
.
Point dns resolving to 127.0.0.1 in /etc/resolv.conf
Add(uncomment) name_servers=127.0.0.1
in
/etc/resolvconf.conf. Then run sudo resolvconf -u
to
generate /etc/resolv.conf
Make Electron Application and Generate .desktop files
After confirming our service can be accessed by *.lan
,
use nativefier
to generate the folder of electron
applications: nativefier app_name.lan
Now the application can launch with:
./app_name-linux-x64/app_name
A simple script here to generate and install the
.desktop
files:
1 |
|
Finally launch our applications with the launcher. Enjoy it :)