feat: URL trailing slashes remove + All pages basepath

This commit is contained in:
NGPixel 2017-04-23 10:56:14 -04:00
parent db16eb72f0
commit f44d0a3c44
6 changed files with 46 additions and 4 deletions

View File

@ -8,12 +8,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- **Auth**: Can now specify Read Access by default for all providers (except Local)
- **View**: MathML and TeX math equations support
- **Configuration Wizard**: Added Public Access option
- **Misc**: Heroku support
- **Navigation**: All Pages section
- **UI**: Beatiful new logo!
### Changed
- **Auth**: Provider Strategies are now only loaded if enabled
- **System**: Updated dependencies
- **Misc**: Trailing slashes in URL are now removed
- **Misc**: Updated dependencies
- **UI**: Footer is now always at the bottom of the page (but not fixed)
### Fixed

View File

@ -32,7 +32,11 @@ module.exports = (alerts, socket) => {
}
},
mounted: function () {
this.fetch('')
let basePath = window.location.pathname.slice(0, -4)
if (basePath.length > 1) {
basePath = basePath.slice(1)
}
this.fetch(basePath)
}
})
}

View File

@ -351,6 +351,12 @@ module.exports = (port, spinner) => {
})
})
).then(() => {
if (process.env.IS_HEROKU) {
return fs.outputJsonAsync('./app/heroku.json', { configured: true })
} else {
return true
}
}).then(() => {
res.json({ ok: true })
}).catch(err => {
res.json({ ok: false, error: err.message })

View File

@ -137,8 +137,12 @@ router.put('/create/*', (req, res, next) => {
/**
* View tree view of all pages
*/
router.get('/all', (req, res, next) => {
res.render('pages/all')
router.use((req, res, next) => {
if (_.endsWith(req.url, '/all')) {
res.render('pages/all')
} else {
next()
}
})
// ==========================================

20
middlewares/seo.js Normal file
View File

@ -0,0 +1,20 @@
'use strict'
const _ = require('lodash')
/**
* SEO Middleware
*
* @param {Express Request} req Express request object
* @param {Express Response} res Express response object
* @param {Function} next next callback function
* @return {any} void
*/
module.exports = function (req, res, next) {
if (req.path.length > 1 && _.endsWith(req.path, '/')) {
let query = req.url.slice(req.path.length) || ''
res.redirect(301, req.path.slice(0, -1) + query)
} else {
return next()
}
}

View File

@ -110,6 +110,12 @@ app.use(flash())
app.use(passport.initialize())
app.use(passport.session())
// ----------------------------------------
// SEO
// ----------------------------------------
app.use(mw.seo)
// ----------------------------------------
// Localization Engine
// ----------------------------------------