Groovy

Nginx-Clojure は組み込みのクロージャー、あるいはJavaまたはGroovyプログラムのためのNGINXモジュールです。一般的にそれらのRing <ring-clojure/ring/blob/master/SPEC>ハンドラに基づいています。

Groovyハンドラの簡単な例がいくつかあります。

インラインの Groovy ハンドラ

nginx.conf 内で

location /groovy {
    handler_type 'groovy';
    handler_code '
    import nginx.clojure.java.NginxJavaRingHandler;
    import java.util.Map;
        public class HelloGroovy implements NginxJavaRingHandler {
            public Object[] invoke(Map<String, Object> request){
                return [200, //http status 200
                       ["Content-Type":"text/html"], //headers map
                       "Hello, Groovy & NGINX!"]; //response body can be string, File or Array/Collection of them
            }
        }
    ';
}

外部的な Groovy ハンドラ

nginx.conf 内で

location /groovy {
    handler_type 'groovy';
    handler_name 'mytest.HelloGroovy';
}

HelloGroovy.groovy の中で

package mytest;
import nginx.clojure.java.NginxJavaRingHandler;
import java.util.Map;
public class HelloGroovy implements NginxJavaRingHandler {
  public Object[] invoke(Map<String, Object> request){
     return
     [200,  //http status 200
      ["Content-Type":"text/html"],//headers map
      "Hello, Groovy & NGINX!" //response body can be string, File or Array/Collection of them
      ];
  }
}

詳細は nginx-clojure.github.ioで見つかります。

TOP
inserted by FC2 system