mirror of
https://github.com/strapi/strapi.git
synced 2025-11-27 07:31:08 +00:00
commit
a6b99cc6a9
@ -340,6 +340,10 @@ It works exactly as before. You need to add `strapi-views` into your app's depen
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"views": {
|
"views": {
|
||||||
|
"enabled": true,
|
||||||
|
"map": {
|
||||||
|
"ejs": "ejs"
|
||||||
|
},
|
||||||
"viewExt": "ejs",
|
"viewExt": "ejs",
|
||||||
"debug": true,
|
"debug": true,
|
||||||
"cache": true
|
"cache": true
|
||||||
|
|||||||
@ -10,6 +10,7 @@ const path = require('path');
|
|||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const consolidate = require('consolidate');
|
const consolidate = require('consolidate');
|
||||||
|
const views = require('koa-views');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public assets hook
|
* Public assets hook
|
||||||
@ -69,7 +70,7 @@ module.exports = strapi => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
strapi.app.use(
|
strapi.app.use(
|
||||||
strapi.koaMiddlewares.views(
|
views(
|
||||||
path.resolve(strapi.config.appPath, strapi.config.paths.views),
|
path.resolve(strapi.config.appPath, strapi.config.paths.views),
|
||||||
opts
|
opts
|
||||||
)
|
)
|
||||||
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "strapi-views",
|
"name": "strapi-middleware-views",
|
||||||
"version": "3.0.0-alpha.6.3",
|
"version": "3.0.0-alpha.6.3",
|
||||||
"description": "Views hook to enable server-side rendering for the Strapi framework",
|
"description": "Views hook to enable server-side rendering for the Strapi framework",
|
||||||
"homepage": "http://strapi.io",
|
"homepage": "http://strapi.io",
|
||||||
@ -16,6 +16,7 @@
|
|||||||
"main": "./lib",
|
"main": "./lib",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"consolidate": "^0.14.5",
|
"consolidate": "^0.14.5",
|
||||||
|
"koa-views": "^6.1.1",
|
||||||
"lodash": "^4.17.4"
|
"lodash": "^4.17.4"
|
||||||
},
|
},
|
||||||
"strapi": {
|
"strapi": {
|
||||||
@ -22,7 +22,8 @@ module.exports = function() {
|
|||||||
'./node_modules/strapi-utils',
|
'./node_modules/strapi-utils',
|
||||||
'./node_modules/strapi-generate*',
|
'./node_modules/strapi-generate*',
|
||||||
'./node_modules/strapi-plugin-*',
|
'./node_modules/strapi-plugin-*',
|
||||||
'./node_modules/strapi-helper-*'
|
'./node_modules/strapi-helper-*',
|
||||||
|
'./node_modules/strapi-middleware-*'
|
||||||
]
|
]
|
||||||
}, (err, files) => {
|
}, (err, files) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@ -46,6 +46,23 @@ module.exports = function() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
const cwd = process.cwd();
|
||||||
|
|
||||||
|
glob(
|
||||||
|
'./node_modules/*(strapi-middleware-*)',
|
||||||
|
{
|
||||||
|
cwd
|
||||||
|
},
|
||||||
|
(err, files) => {
|
||||||
|
if (err) {
|
||||||
|
return reject(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
mountMiddlewares.call(this, files, cwd)(resolve, reject);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}),
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
const cwd = path.resolve(__dirname, '..', 'middlewares');
|
const cwd = path.resolve(__dirname, '..', 'middlewares');
|
||||||
|
|
||||||
@ -124,7 +141,8 @@ const mountMiddlewares = function (files, cwd) {
|
|||||||
return (resolve, reject) =>
|
return (resolve, reject) =>
|
||||||
parallel(
|
parallel(
|
||||||
files.map(p => cb => {
|
files.map(p => cb => {
|
||||||
const name = p.split('/')[1];
|
const name = p.replace(/^.\/node_modules\/strapi-middleware-/, './')
|
||||||
|
.split('/')[1];
|
||||||
|
|
||||||
this.middleware[name] = {
|
this.middleware[name] = {
|
||||||
loaded: false
|
loaded: false
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user