Thursday, August 31, 2017

Javascript touch events

Javascript has the following touch events:
  • touchstart
  • touchmove
  • touchend
  • touchenter
  • touchleave
  • touchcancel
We usually use the following code snippet to detect touch event support

if ('ontouchstart' in window) {
  /* browser with Touch Events
     running on touch-capable device */
}

if (('ontouchstart' in window) ||
     (navigator.maxTouchPoints > 0) ||
     (navigator.msMaxTouchPoints > 0)) {
      /* browser with either Touch Events or Pointer Events (from Microsoft, outdated)
         running on touch-capable device */
}

To support both touch-capable device and desktop mouse input, we can listen to both touch event and click event, something like below

blah.addEventListener('touchend', function(e) {
  /* prevent delay and simulated mouse events */
  e.preventDefault();
  someFunction()
});
blah.addEventListener('click', someFunction);

If we need all touch events handling for Mobile web, suggest to check out some open source libraries, like jQuery Mobile, hammerjs, or jQuery-Touch-Events.

Wednesday, August 30, 2017

nginx proxy_pass 502 Bad gateway

I use proxy_pass to proxy local API requests to our dev servers, something like

proxy_pass https://dev-server.com/api

All of a sudden, it stops working with a "502 Bad Gateway" error in browser DevTool network. However I can access https://dev-server.com/api directly using web browser.

It is obvious that nginx upstream fails for some reason. I googled a lot, and most discussions are relating to nginx configuration. However, I didn't change anything to nginx configuration before it stops working. Something happened on api server side?

Yes, our api server turned off TLSv1.0 due to security concern. I checked my local nginx and openssl versions, and realized we have 2 options:
1. Upgrade openssl version
2. Rollback api server changes to allow TLSv1.0

$ /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.0.15

$ openssl version -a
OpenSSL 0.9.8zh 14 Jan 2016
built on: Jan 23 2017
platform: darwin64-x86_64-llvm
options:  bn(64,64) md2(int) rc4(ptr,char) des(idx,cisc,16,int) blowfish(idx)
compiler: -arch x86_64 -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -fasm-blocks -O3 -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DL_ENDIAN -DMD32_REG_T=int -DOPENSSL_NO_IDEA -DOPENSSL_PIC -DOPENSSL_THREADS -DZLIB -mmacosx-version-min=10.6
OPENSSLDIR: "/System/Library/OpenSSL"

How to enable TLSv1.2 in Nignx?
https://askubuntu.com/questions/319192/how-to-enable-tls-1-2-in-nginx

ssl_protocols TLSv1.2 TLSv1.1 TLSv1;

ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA;
ssl_prefer_server_ciphers on;

Tuesday, August 29, 2017

www.calligraphyus.com website goes live

我们使用Google site很快搭建了一个书法网站来介绍华风书社,非常好用,从框架到版面,大概也就1-2个小时的时间,唯一的问题是存储空间有限,手机访问支持不好,在这个mobile first的时代,感觉有点落伍。我们不想去购买G Suite, 所以就将就了。然后去Godaddy买了个域名,配了下DNS就可以访问 华风书社 (www.calligraphyus.com)

推广网站倒是个头痛的事情,除了传统的SEO优化外,可能最直接的方法就是购买Google AdWords了,但这个每天都要支出的,所以目前不太适合。我们还是看看其他方法,比如多写些blog, 多发布些商家信息,多加些外链。

定搜索关键词也是个头疼的事情,如果有明确的方向或者明确的竞争对手就好些,不然自己就要揣摩用户查找的习惯。我们书社的目的是在旧金山湾区推广书法,教授书法,所以目前定下来的关键词是:湾区 书法。 一个是地点信息,一个是主题,书法学习,书法老师,书法讲座,书法探讨,传统书法等等都有这个主语。

外链的做法就是在湾区比较流行的论坛上或商家黄页上发布信息。

希望越来越多的对中国传统书法感兴趣的湾区家长能够搜到我们的 www.calligraphyus.com