Browse Source

feat: URL trailing slashes remove + All pages basepath

pull/89/head
NGPixel 7 years ago
parent
commit
f44d0a3c44
6 changed files with 46 additions and 4 deletions
  1. 4
      CHANGELOG.md
  2. 6
      client/js/pages/all.js
  3. 6
      configure.js
  4. 8
      controllers/pages.js
  5. 20
      middlewares/seo.js
  6. 6
      server.js

4
CHANGELOG.md

@ -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) - **Auth**: Can now specify Read Access by default for all providers (except Local)
- **View**: MathML and TeX math equations support - **View**: MathML and TeX math equations support
- **Configuration Wizard**: Added Public Access option - **Configuration Wizard**: Added Public Access option
- **Misc**: Heroku support
- **Navigation**: All Pages section - **Navigation**: All Pages section
- **UI**: Beatiful new logo! - **UI**: Beatiful new logo!
### Changed ### Changed
- **Auth**: Provider Strategies are now only loaded if enabled - **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) - **UI**: Footer is now always at the bottom of the page (but not fixed)
### Fixed ### Fixed

6
client/js/pages/all.js

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

6
configure.js

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

8
controllers/pages.js

@ -137,8 +137,12 @@ router.put('/create/*', (req, res, next) => {
/** /**
* View tree view of all pages * 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

@ -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()
}
}

6
server.js

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

Loading…
Cancel
Save