Nginx dev config for Quasar HMR with backend api

To serve dev site on static url of https://dev.host.to/$project through nginx server

Nginx snippet

/etc/nginx/snippets/quasar.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
set $devport 9999;

# serve index.php at https://dev.host.to/$project/backend
location ~ ^/(?<project>\w+)/backend/ {
try_files $uri $uri/ /$project/backend/index.php$is_args$args;
}

# serve web socket of quasar dev server at https://dev.host.to/sockjs-node for HMR
location /sockjs-node {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://127.0.0.1:$devport;
}

# serve quasar dev server at https://dev.host.to/$project/
location ~ ^/(?<project>\w+)/(?<path>.*) {
proxy_pass http://127.0.0.1:$devport/$path;
}

Quasar conf

quasar.conf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module.exports = function (ctx) {
return {
// ...
build: {
publicPath: '/$project/',
forceDevPublicPath: true,
vueRouterMode: 'history',
},

// ...
devServer: {
publicPath: '/',
historyApiFallback: true,
public: 'https://dev.host.to/$project',
port: 9999,
},
}
}

Using gmail api via service account credential

For some reason, I need to grab a mail attachment to store its content into database everyday.

So obviously I can’t use the normal OAuth approach because no one can authorized this action every day, that leaves service account to get this thing done.

First, I need a service account, follow the instructions of Creating a service account section

And as a service account to access gmail, I have to impersonate as some real user to access thier mails, I could only do that in a Google Apps for Work domain.

To do so, I checked the next section of document, Delegating domain-wide authority to the service account.

But I can’t find the client id on the web console anywhere, I do find one client_id field in the .json key file though, which the Manage API client access panel doesn’t accept it at all.

Read More

Git daemon

Create a daemon for readonly git clone access

1
2
3
4
5
6
git daemon --base-path=/path-to-gitolite/repositories --export-all
# --export-all option to export all repos
# or touch a git-daemon-export-ok file under repos needs to be export

# how to access
git clone git://git.example.com/ex-repo

New hexo post auto open with editor

Just add a simple script (from here)

/path-to-hexo-root/scripts/open-new.js
1
2
3
4
5
6
7
8
9
10
11
var exec = require('child_process').exec;
hexo.on('new', function(data) {
exec('hexo server'); // start preview server
setTimeout(function() {
// couldn't find a server started event
// so just workaround to do in 3s later
exec('open -a "Google Chrome" "http://0.0.0.0:4000"'); // open preview url
// open with editor (in this case using Sublime Text and also open cwd together)
exec('open -a "Sublime Text" '+process.cwd()+' '+data.path);
}, 3000);
});

Redmine repositories from gitolite

Only two steps:

  1. Let www-data have read access of /path-to-gitolite-root/repositories

    1
    2
    3
    4
    5
    6
    7
    cd /path-to-gitolite-root

    # let all repos readable for all users, but not writable except owner
    chmod a+rX,go-w -R repositories

    # keep gitolite-admin remains only readable/writable by owner
    chmod go-rwX -R repositories/gitolite-admin.git
  2. Keep it that way when gitolite add any new things

    /path-to-gitolite-root/.gitolite.rc
    1
    2
    3
    4
    5
    %RC = (
    ...
    #UMASK => 0077,
    UMASK => 0022, # now any new repo will keep rx permissions of groups & others
    ...

mutt on OS X

Need Homebrew

1
2
3
4
5
6
7
brew install mutt

# made mutt to read mail from /var/mail
echo 'set spoolfile=/var/mail/$USER' > ~/.muttrc

# grant permission to edit mail or it will be read-only
dseditgroup -o edit -u $USER -p -a $USER -t user mail

Nginx with Passenger

install a nginx server integrating Passenger

using ruby in RVM for Passenger, also included bundler with RVM
1
2
3
4
5
6
7
8
9
10
# Install RVM for server
curl -sSL https://get.rvm.io | sudo bash -s stable --ruby
vim /etc/group # add all user using rvm into rvm group

# speed up gem install by avoiding docs
echo "gem: --no-ri --no-rdoc" > ~/.gemrc

# install Bundler using RVM
gem install rubygems-bundler
gem install bundler

Install Passenger follow official introduction

Then setup RVM ruby for passenger

1
passenger-config about ruby-command

Copy output after “To use in Nginx” to /etc/nginx/passenger.conf
Should look like this

/etc/nginx/passenger.conf
1
2
3
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/local/rvm/gems/ruby-2.3.0/wrappers/ruby;
# replace /usr/bin/passenger_free_ruby to realpath from `passenger-config about ruby-command`