Differences
This shows you the differences between two versions of the page.
— |
documentation:2.1:nodehandler [2019/08/31 09:30] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Node.js handler ====== | ||
+ | Since version 2.0, a beta Node.js handler is available on [[https:// | ||
+ | |||
+ | Up-to-date documentation is available on GitHub. | ||
+ | |||
+ | ===== Examples ===== | ||
+ | |||
+ | **Important things**: | ||
+ | * Rules and headers must be written in javascript for these hosts //(example '' | ||
+ | * Multi-lines are not supported in lemonldap-ng.ini | ||
+ | * Virtualhosts handled by node-lemonldap-ng-handler must be explicitly declared in your '' | ||
+ | <code ini> | ||
+ | [node-handler] | ||
+ | |||
+ | nodeVhosts = test.example.com, | ||
+ | </ | ||
+ | |||
+ | ==== Use it as FastCGI server (application protection only) ==== | ||
+ | |||
+ | === FastCGI server === | ||
+ | |||
+ | <file javascript server.js> | ||
+ | var handler = require(' | ||
+ | |||
+ | handler.init({ | ||
+ | configStorage: | ||
+ | " | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | handler.nginxServer({ | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | === Nginx configuration === | ||
+ | |||
+ | <file nginx nginx.conf> | ||
+ | server { | ||
+ | #... | ||
+ | # Internal authentication request | ||
+ | location = /lmauth { | ||
+ | internal; | ||
+ | include / | ||
+ | fastcgi_pass localhost: | ||
+ | |||
+ | # Drop post datas | ||
+ | fastcgi_pass_request_body | ||
+ | fastcgi_param CONTENT_LENGTH ""; | ||
+ | |||
+ | # Keep original hostname | ||
+ | fastcgi_param HOST $http_host; | ||
+ | |||
+ | # Keep original request (LLNG server will receive /lmauth) | ||
+ | fastcgi_param X_ORIGINAL_URI | ||
+ | } | ||
+ | |||
+ | # Client requests | ||
+ | location / { | ||
+ | auth_request /lmauth; | ||
+ | auth_request_set $lmremote_user $upstream_http_lm_remote_user; | ||
+ | auth_request_set $lmlocation $upstream_http_location; | ||
+ | error_page 401 $lmlocation; | ||
+ | include conf/ | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Use it to protect an express app ==== | ||
+ | |||
+ | <file javascript app.js> | ||
+ | // Variables | ||
+ | var express = require(' | ||
+ | var app = express(); | ||
+ | var handler = require(' | ||
+ | |||
+ | // initialize handler (optional args) | ||
+ | handler.init({ | ||
+ | configStorage: | ||
+ | " | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | // and load it | ||
+ | app.use(handler.run); | ||
+ | |||
+ | // Then simply use your express app | ||
+ | app.get('/', | ||
+ | return res.send(' | ||
+ | }); | ||
+ | app.listen(3000, | ||
+ | return console.log(' | ||
+ | }); | ||
+ | </ |