@julian sadly ..
My configuration is behind a nginx proxy, where the NodeBB install is on a seperate server but part of the domains URL, e.g. www.example.com/bb
The window.config
is also showing { .. relative_path: '/bb' .. }
correctly, though I'm not using NodeBB's frontend nor an iframe. I've implemented the forum within the main DOM of the corporate website and wrote a custom requirejs frontend where the forum, chats and group-chats are completely integrated with the DOM itself and doesn't get stuck on usability due to the iframe. It's almost as simple as requesting the templates under /assets
and request the data, render, translate and add or remove some bits from the compiled view.
Back to write-api
The config.json
used
"url":"http://www.example.com/bb",
"port":4567,
"secret": "587c152e-...",
"database": "mongo",
"mongo": {
"host": "127.0.0.1",
"port": "27017",
....
},
"socket.io": {
"origins": "*:*"
},
etc ..
Nginx proxy is configured with proxy_pass
"locally"
location ^~ /bb {
proxy_pass http://nodebb-server-ip:4567/bb;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
proxy_read_timeout 1800;
client_max_body_size 4G;
}
Simple test at the beginning of nodebb-plugins-write-api/routes/v1/middleware.js
Middleware.requireUser = function(req, res, next) {
var writeApi = require.main.require('nodebb-plugin-write-api');
var routeMatch;
console.log('req.originalUrl: '+req.originalUrl);
console.log('matching: [/^\/api\/v\d+\/users\/(\d+)\/tokens$/)]');
console.log(req.originalUrl.match(/^\/api\/v\d+\/users\/(\d+)\/tokens$/));
console.log('matching: [/^(.*?)\/api\/v\d+\/users\/(\d+)\/tokens$/)]');
console.log(req.originalUrl.match(/^(.*?)\/api\/v\d+\/users\/(\d+)\/tokens$/));
Gives following output in dev mode:
20/6 09:28:14 [8841] - info: NodeBB Ready
20/6 09:28:14 [8841] - info: Enabling 'trust proxy'
20/6 09:28:14 [8841] - info: NodeBB is now listening on: 0.0.0.0:4567
req.originalUrl: /bb/api/v1/users/99/tokens
matching: [/^/api/vd+/users/(d+)/tokens$/)]
null
matching: [/^(.*?)/api/vd+/users/(d+)/tokens$/)]
[ '/bb/api/v1/users/99/tokens',
'/bb',
'99',
index: 0,
input: '/bb/api/v1/users/99/tokens' ]
The routeMatch
index for getting the :uid
then changes from [1]
to [2]
// If token generation route is hit, check password instead
var uid = routeMatch[2];
There is probably a better solution for (.*?)
instead.