【问题标题】:Invalid Cloudinary ConfigurationCloudinary 配置无效
【发布时间】:2014-11-28 12:56:44
【问题描述】:

我是 keystone 的新手,我正在尝试部署一个简单的网站模板来熟悉这项技术,我已经下载了所有必需的模块并创建了一个 keystone.js 文件和包含所有依赖项的 package.json 文件。但是,当我尝试在终端中运行 keystone.js 时,我得到以下信息:

 Error: Invalid Configuration

 CloudinaryImage fields (Gallery.heroImage) require the "cloudinary config" option to be set.

 See http://keystonejs.com/docs/configuration/#cloudinary for more information.

我已经用 cloudinary 设置了一个帐户并使用 npm install 来确保它已安装在系统中,但它显然找不到配置。我假设有一个简单的解决方案,我只需将我的配置字段放在代码的正确位置,但我似乎找不到任何关于在哪里插入我的帐户详细信息的说明。任何帮助将不胜感激,如果我遗漏了任何重要代码,请告诉我。

keystone.js:

    require('dotenv').load();

    // Require keystone
   var keystone = require('keystone'),
handlebars = require('express3-handlebars');


    // Initialise Keystone with your project's configuration.
   // See http://keystonejs.com/guide/config for available options
   // and documentation.


   keystone.init({

'name': 'Tech Website',
'brand': 'Tech Website',

'less': 'public',
'static': 'public',
'favicon': 'public/favicon.ico',
'views': 'templates/views',
'view engine': 'hbs',

'custom engine': handlebars.create({
    layoutsDir: 'templates/views/layouts',
    partialsDir: 'templates/views/partials',
    defaultLayout: 'default',
    helpers: new require('./templates/views/helpers')(),
    extname: '.hbs'
}).engine,

'auto update': true,
'session': true,
'auth': true,
'user model': 'Yes',
'cookie secret': 'pUO>=q^~Z.h]~pO"k;:]dTcTb:6pT3Xyassxdk>9K]7J0MGqSWWr;$rs6lG<XLdB'

});

    // Load your project's Models

keystone.import('models');

    // Setup common locals for your templates. The following are required for the
   // bundled templates and layouts. Any runtime locals (that should be set uniquely
  // for each request) should be added to ./routes/middleware.js

keystone.set('locals', {
_: require('underscore'),
env: keystone.get('env'),
utils: keystone.utils,
editable: keystone.content.editable
    });

    // Load your project's Routes

    keystone.set('routes', require('./routes'));

    // Setup common locals for your emails. The following are required by Keystone's
    // default email templates, you may remove them if you're using your own.

    // Configure the navigation bar in Keystone's Admin UI

    keystone.set('nav', {
'posts': ['posts', 'post-categories'],
'galleries': 'galleries',
'enquiries': 'enquiries',
'yes': 'yes'
});

// Start Keystone to connect to your database and initialise the web server

.start();

package.json

{
 "name": "tech-website",
  "version": "0.0.0",
  "private": true,
  "dependencies": {
  "keystone": "~0.2.27",
  "async": "~0.9.0",
  "underscore": "~1.7.0",
  "moment": "~2.8.1",
  "express3-handlebars": "~0.5.0",
  "handlebars": "^2.0.0-alpha.2",
  "dotenv": "0.4.0"
  },
  "devDependencies": {
  "grunt": "~0.4.4",
  "grunt-express-server": "~0.4.17",
  "grunt-contrib-watch": "~0.6.1",
  "grunt-contrib-jshint": "~0.7.1",
  "jshint-stylish": "~0.1.3",
  "load-grunt-tasks": "~0.4.0",
  "grunt-node-inspector": "~0.1.5",
  "time-grunt": "~0.3.1",
  "grunt-concurrent": "~0.5.0",
  "grunt-nodemon": "~0.2.1",
  "open": "0.0.5"
},
  "engines": {
  "node": ">=0.10.22",
  "npm": ">=1.3.14"
},
"scripts": {
"start": "node keystone.js"
},
"main": "keystone.js"
}

【问题讨论】:

    标签: node.js file config cloudinary keystonejs


    【解决方案1】:

    您可以通过多种方式在 KeystoneJS 应用中配置 Cloudinary

    一个选项是设置CLOUDINARY_URL 环境变量。您可以在 .env 文件中执行此操作,因为您使用的是 dotenv

    CLOUDINARY_URL=cloudinary://api_key:api_secret@cloud_name
    

    第二种选择是在您的 Keystonejs 应用程序中设置 cloudinary config 设置。

    您可以在 keystone.init() 中执行此操作

    keystone.init({
        ...
        'cloudinary config': 'cloudinary://api_key:api_secret@cloud_name',
        ...
    });
    

    ...或使用keystone.set() 方法。

    keystone.set('cloudinary config', 'cloudinary://api_key:api_secret@cloud_name' );
    

    这些都在KeystonsJS Configuration 页面上进行了详细说明,但不再存在。

    【讨论】:

    • 我这样做了,但在 keystone admin/gallery 中它说No galleries found.
    • 我假设您使用了自己的 Cloudinary 帐户。如果您从未创建/上传任何画廊,管理员应该说“未找到画廊”。创建画廊并上传一些照片。
    • 默认情况下 cloudinary 提供一张照片!我还尝试使用 keystonejs 提供的示例中的 cloudinary 密钥。它仍然显示相同的消息
    • Keystone 不会“自动”在 Cloudinary 中拾取照片。您的画廊表中必须有一条指向图像的记录。
    • 我创建了一个画廊模型var Gallery = new keystone.List('Gallery', { autokey: { from: 'name', path: 'key', unique: true }, nodelete:true, nocreate:true }); Gallery.add({ name: { type: String, required: true }, publishedDate: { type: Date, default: Date.now }, images: { type: Types.CloudinaryImages } }); Gallery.register(); 这就是我设置配置的方式keystone.set('cloudinary config', 'cloudinary://333779167276662:_8jbSi9FB3sWYrfimcl8VKh34rI@keystone-demo' ); keystone.start();
    【解决方案2】:

    添加一些东西 -

    实际上对我有用的是当我将配置设置部分放在

    keystone.init 部分。使用 setter 对我不起作用。

    keystone.init({
        ...
        'cloudinary config': 'cloudinary://api_key:api_secret@cloud_name',
        ...
    });
    

    上面的代码是唯一可以完美运行的代码。

    【讨论】:

    • 遇到了类似的问题,只要我将 setter 移到 init 上方就可以工作。
    • 这里同样成功地将setter移到init之上。为我解决了这个问题。
    【解决方案3】:

    这是我部署到heroku的方式。在 keystone.js 中添加一个块以使用环境变量:

    if (keystone.get('env') == 'production'){
        keystone.set('cloudinary config', process.env.CLOUDINARY_URL);
        keystone.set('cookie secret', process.env.COOKIE_SECRET);
        keystone.set('mandrill api key', process.env.MANDRILL_API_KEY);
    }
    

    然后通过命令行在你的heroku实例上设置环境变量:

    $ heroku config:set MANDRILL_API_KEY=YOUR_API_KEY
    $ heroku config:set CLOUDINARY_URL=cloudinary://api_key:api_secret@cloud_name
    $ heroku config:set NODE_ENV=production
    $ heroku config:set COOKIE_SECRET=YOUR_COOKIE_STRING
    

    【讨论】:

      猜你喜欢
      • 2014-09-25
      • 2018-05-20
      • 2015-10-22
      • 2015-12-28
      • 1970-01-01
      • 2021-06-15
      • 2017-08-30
      • 2015-07-17
      • 2018-02-08
      相关资源
      最近更新 更多