mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
Home route (#7039)
* fix: WIP home fix * remove console.log * fix: #6949 on redis run all tests in subfolder /forum fix URI errors fix sping/ping
This commit is contained in:
committed by
GitHub
parent
cd46febdd0
commit
1f918ca8f8
@@ -8,7 +8,7 @@ before_script:
|
|||||||
- sleep 15 # wait for mongodb to be ready
|
- sleep 15 # wait for mongodb to be ready
|
||||||
- "mongo mydb_test --eval 'db.createUser({user:\"travis\", pwd: \"test\", roles: []});'"
|
- "mongo mydb_test --eval 'db.createUser({user:\"travis\", pwd: \"test\", roles: []});'"
|
||||||
- sh -c "if [ '$DB' = 'mongodb' ]; then node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"mongo\\\",\\\"mongo:host\\\":\\\"127.0.0.1\\\",\\\"mongo:port\\\":27017,\\\"mongo:username\\\":\\\"\\\",\\\"mongo:password\\\":\\\"\\\",\\\"mongo:database\\\":0,\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"hAN3Eg8W\\\",\\\"admin:password:confirm\\\":\\\"hAN3Eg8W\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":27017,\\\"database\\\":0}\"; fi"
|
- sh -c "if [ '$DB' = 'mongodb' ]; then node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"mongo\\\",\\\"mongo:host\\\":\\\"127.0.0.1\\\",\\\"mongo:port\\\":27017,\\\"mongo:username\\\":\\\"\\\",\\\"mongo:password\\\":\\\"\\\",\\\"mongo:database\\\":0,\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"hAN3Eg8W\\\",\\\"admin:password:confirm\\\":\\\"hAN3Eg8W\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":27017,\\\"database\\\":0}\"; fi"
|
||||||
- sh -c "if [ '$DB' = 'redis' ]; then node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"redis\\\",\\\"redis:host\\\":\\\"127.0.0.1\\\",\\\"redis:port\\\":6379,\\\"redis:password\\\":\\\"\\\",\\\"redis:database\\\":0,\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"hAN3Eg8W\\\",\\\"admin:password:confirm\\\":\\\"hAN3Eg8W\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":6379,\\\"database\\\":0}\"; fi"
|
- sh -c "if [ '$DB' = 'redis' ]; then node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567/forum\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"redis\\\",\\\"redis:host\\\":\\\"127.0.0.1\\\",\\\"redis:port\\\":6379,\\\"redis:password\\\":\\\"\\\",\\\"redis:database\\\":0,\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"hAN3Eg8W\\\",\\\"admin:password:confirm\\\":\\\"hAN3Eg8W\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":6379,\\\"database\\\":0}\"; fi"
|
||||||
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'create database nodebb;' -U postgres; psql -c 'create database travis_ci_test;' -U postgres; node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"postgres\\\",\\\"postgres:host\\\":\\\"127.0.0.1\\\",\\\"postgres:port\\\":5432,\\\"postgres:password\\\":\\\"\\\",\\\"postgres:database\\\":\\\"nodebb\\\",\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"hAN3Eg8W\\\",\\\"admin:password:confirm\\\":\\\"hAN3Eg8W\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":5432,\\\"username\\\":\\\"postgres\\\",\\\"database\\\":\\\"travis_ci_test\\\"}\"; fi"
|
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'create database nodebb;' -U postgres; psql -c 'create database travis_ci_test;' -U postgres; node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"postgres\\\",\\\"postgres:host\\\":\\\"127.0.0.1\\\",\\\"postgres:port\\\":5432,\\\"postgres:password\\\":\\\"\\\",\\\"postgres:database\\\":\\\"nodebb\\\",\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"hAN3Eg8W\\\",\\\"admin:password:confirm\\\":\\\"hAN3Eg8W\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":5432,\\\"username\\\":\\\"postgres\\\",\\\"database\\\":\\\"travis_ci_test\\\"}\"; fi"
|
||||||
after_success:
|
after_success:
|
||||||
- "npm run coveralls"
|
- "npm run coveralls"
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ var plugins = require('../plugins');
|
|||||||
exports.handleURIErrors = function (err, req, res, next) {
|
exports.handleURIErrors = function (err, req, res, next) {
|
||||||
// Handle cases where malformed URIs are passed in
|
// Handle cases where malformed URIs are passed in
|
||||||
if (err instanceof URIError) {
|
if (err instanceof URIError) {
|
||||||
var tidMatch = req.path.match(/^\/topic\/(\d+)\//);
|
const cleanPath = req.path.replace(new RegExp('^' + nconf.get('relative_path')), '');
|
||||||
var cidMatch = req.path.match(/^\/category\/(\d+)\//);
|
var tidMatch = cleanPath.match(/^\/topic\/(\d+)\//);
|
||||||
|
var cidMatch = cleanPath.match(/^\/category\/(\d+)\//);
|
||||||
|
|
||||||
if (tidMatch) {
|
if (tidMatch) {
|
||||||
res.redirect(nconf.get('relative_path') + tidMatch[0]);
|
res.redirect(nconf.get('relative_path') + tidMatch[0]);
|
||||||
@@ -49,7 +50,7 @@ exports.handleErrors = function (err, req, res, next) { // eslint-disable-line n
|
|||||||
// Display NodeBB error page
|
// Display NodeBB error page
|
||||||
var status = parseInt(err.status, 10);
|
var status = parseInt(err.status, 10);
|
||||||
if ((status === 302 || status === 308) && err.path) {
|
if ((status === 302 || status === 308) && err.path) {
|
||||||
return res.locals.isAPI ? res.set('X-Redirect', err.path).status(200).json(err.path) : res.redirect(err.path);
|
return res.locals.isAPI ? res.set('X-Redirect', err.path).status(200).json(err.path) : res.redirect(nconf.get('relative_path') + err.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
winston.error(req.path + '\n', err);
|
winston.error(req.path + '\n', err);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
const async = require('async');
|
||||||
var db = require('../database');
|
const nconf = require('nconf');
|
||||||
|
const db = require('../database');
|
||||||
|
|
||||||
module.exports.ping = function (req, res, next) {
|
module.exports.ping = function (req, res, next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -9,7 +10,7 @@ module.exports.ping = function (req, res, next) {
|
|||||||
db.getObject('config', next);
|
db.getObject('config', next);
|
||||||
},
|
},
|
||||||
function () {
|
function () {
|
||||||
res.status(200).send(req.path === '/sping' ? 'healthy' : '200');
|
res.status(200).send(req.path === nconf.get('relative_path') + '/sping' ? 'healthy' : '200');
|
||||||
},
|
},
|
||||||
], next);
|
], next);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -87,18 +87,7 @@ function groupRoutes(app, middleware, controllers) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function (app, middleware, callback) {
|
module.exports = function (app, middleware, callback) {
|
||||||
var routers = [
|
const router = express.Router();
|
||||||
express.Router(), // plugin router
|
|
||||||
express.Router(), // main app router
|
|
||||||
express.Router(), // auth router
|
|
||||||
];
|
|
||||||
var pluginRouter = routers[0];
|
|
||||||
pluginRouter.render = function () {
|
|
||||||
app.render.apply(app, arguments);
|
|
||||||
};
|
|
||||||
|
|
||||||
var router = routers[1];
|
|
||||||
var authRouter = routers[2];
|
|
||||||
|
|
||||||
var relativePath = nconf.get('relative_path');
|
var relativePath = nconf.get('relative_path');
|
||||||
var ensureLoggedIn = require('connect-ensure-login');
|
var ensureLoggedIn = require('connect-ensure-login');
|
||||||
@@ -111,11 +100,25 @@ module.exports = function (app, middleware, callback) {
|
|||||||
|
|
||||||
// handle custom homepage routes
|
// handle custom homepage routes
|
||||||
router.use('/', controllers.home.rewrite);
|
router.use('/', controllers.home.rewrite);
|
||||||
pluginRouter.use('/', controllers.home.rewrite);
|
|
||||||
|
|
||||||
// homepage handled by `action:homepage.get:[route]`
|
// homepage handled by `action:homepage.get:[route]`
|
||||||
setupPageRoute(router, '/', middleware, [], controllers.home.pluginHook);
|
setupPageRoute(router, '/', middleware, [], controllers.home.pluginHook);
|
||||||
|
|
||||||
|
async.series([
|
||||||
|
async.apply(plugins.reloadRoutes, router),
|
||||||
|
async.apply(authRoutes.reloadRoutes, router),
|
||||||
|
async.apply(addCoreRoutes, app, router, middleware),
|
||||||
|
async.apply(user.addInterstitials),
|
||||||
|
function (next) {
|
||||||
|
winston.info('Routes added');
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
], function (err) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function addCoreRoutes(app, router, middleware, callback) {
|
||||||
adminRoutes(router, middleware, controllers);
|
adminRoutes(router, middleware, controllers);
|
||||||
metaRoutes(router, middleware, controllers);
|
metaRoutes(router, middleware, controllers);
|
||||||
apiRoutes(router, middleware, controllers);
|
apiRoutes(router, middleware, controllers);
|
||||||
@@ -132,9 +135,8 @@ module.exports = function (app, middleware, callback) {
|
|||||||
userRoutes(router, middleware, controllers);
|
userRoutes(router, middleware, controllers);
|
||||||
groupRoutes(router, middleware, controllers);
|
groupRoutes(router, middleware, controllers);
|
||||||
|
|
||||||
routers.forEach((router) => {
|
var relativePath = nconf.get('relative_path');
|
||||||
app.use(relativePath || '/', router);
|
app.use(relativePath || '/', router);
|
||||||
});
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
require('./debug')(app, middleware, controllers);
|
require('./debug')(app, middleware, controllers);
|
||||||
@@ -184,17 +186,5 @@ module.exports = function (app, middleware, callback) {
|
|||||||
app.use(controllers['404'].handle404);
|
app.use(controllers['404'].handle404);
|
||||||
app.use(controllers.errors.handleURIErrors);
|
app.use(controllers.errors.handleURIErrors);
|
||||||
app.use(controllers.errors.handleErrors);
|
app.use(controllers.errors.handleErrors);
|
||||||
|
setImmediate(callback);
|
||||||
// Add plugin routes
|
}
|
||||||
async.series([
|
|
||||||
async.apply(plugins.reloadRoutes, pluginRouter),
|
|
||||||
async.apply(authRoutes.reloadRoutes, authRouter),
|
|
||||||
async.apply(user.addInterstitials),
|
|
||||||
function (next) {
|
|
||||||
winston.info('Routes added');
|
|
||||||
next();
|
|
||||||
},
|
|
||||||
], function (err) {
|
|
||||||
callback(err);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -2144,7 +2144,7 @@ describe('Controllers', function () {
|
|||||||
assert.equal(res.statusCode, 200);
|
assert.equal(res.statusCode, 200);
|
||||||
assert(body.title);
|
assert(body.title);
|
||||||
assert(body.template);
|
assert(body.template);
|
||||||
assert.equal(body.url, '/compose');
|
assert.equal(body.url, nconf.get('relative_path') + '/compose');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -2165,7 +2165,7 @@ describe('Controllers', function () {
|
|||||||
assert.equal(res.statusCode, 200);
|
assert.equal(res.statusCode, 200);
|
||||||
assert(body.title);
|
assert(body.title);
|
||||||
assert.strictEqual(body.template.name, '');
|
assert.strictEqual(body.template.name, '');
|
||||||
assert.strictEqual(body.url, '/compose');
|
assert.strictEqual(body.url, nconf.get('relative_path') + '/compose');
|
||||||
|
|
||||||
plugins.unregisterHook('myTestPlugin', 'filter:composer.build', hookMethod);
|
plugins.unregisterHook('myTestPlugin', 'filter:composer.build', hookMethod);
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ nconf.defaults({
|
|||||||
relative_path: '',
|
relative_path: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var urlObject = url.parse(nconf.get('url'));
|
||||||
|
var relativePath = urlObject.pathname !== '/' ? urlObject.pathname : '';
|
||||||
|
nconf.set('relative_path', relativePath);
|
||||||
|
|
||||||
if (!nconf.get('isCluster')) {
|
if (!nconf.get('isCluster')) {
|
||||||
nconf.set('isPrimary', 'true');
|
nconf.set('isPrimary', 'true');
|
||||||
nconf.set('isCluster', 'true');
|
nconf.set('isCluster', 'true');
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ describe('Upload Controllers', function () {
|
|||||||
assert.equal(res.statusCode, 200);
|
assert.equal(res.statusCode, 200);
|
||||||
assert(Array.isArray(body));
|
assert(Array.isArray(body));
|
||||||
assert(body[0].url);
|
assert(body[0].url);
|
||||||
var name = body[0].url.replace(nconf.get('upload_url'), '');
|
var name = body[0].url.replace(nconf.get('relative_path') + nconf.get('upload_url'), '');
|
||||||
socketUser.deleteUpload({ uid: regularUid }, { uid: regularUid, name: name }, function (err) {
|
socketUser.deleteUpload({ uid: regularUid }, { uid: regularUid, name: name }, function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
db.getSortedSetRange('uid:' + regularUid + ':uploads', 0, -1, function (err, uploads) {
|
db.getSortedSetRange('uid:' + regularUid + ':uploads', 0, -1, function (err, uploads) {
|
||||||
|
|||||||
Reference in New Issue
Block a user