Ghost/core/server/apps/private-blogging/lib/router.js
kirrg001 0046dce39f Dynamic Routing Beta: Better template support
refs #9601

- single or multiple template definition
- possible formats:

```
routes:
  /about/: about
```

```
routes:
  /about/:
    template: about
```

```
routes:
  /about/:
    template:
      - about
      - me
```

```
collections
  /posts/:
    template:
      - posts
      - general
```

```
collections
  /posts/:
    template: posts
```
2018-06-21 16:22:45 +02:00

48 lines
1.2 KiB
JavaScript

const path = require('path'),
express = require('express'),
middleware = require('./middleware'),
bodyParser = require('body-parser'),
routing = require('../../../services/routing'),
brute = require('../../../web/middleware/brute'),
templateName = 'private',
privateRouter = express.Router();
function _renderer(req, res) {
// Note: this is super similar to the config middleware used in channels
// @TODO refactor into to something explicit & DRY this up
res._route = {
type: 'custom',
templates: templateName,
defaultTemplate: path.resolve(__dirname, 'views', templateName + '.hbs')
};
// Renderer begin
// Format data
var data = {};
if (res.error) {
data.error = res.error;
}
// Render Call
return routing.helpers.renderer(req, res, data);
}
// password-protected frontend route
privateRouter
.route('/')
.get(
middleware.isPrivateSessionAuth,
_renderer
)
.post(
bodyParser.urlencoded({extended: true}),
middleware.isPrivateSessionAuth,
brute.privateBlog,
middleware.authenticateProtection,
_renderer
);
module.exports = privateRouter;
module.exports.renderer = _renderer;