6

私は keystone を初めて使用し、テクノロジーに慣れるために単純な Web サイト テンプレートをデプロイしようとしています。必要なモジュールをすべてダウンロードし、すべての依存関係を含む 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();

パッケージ.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"
}
4

3 に答える 3

7

CloudinaryKeystoneJS アプリで構成できる方法は複数あります。

1 つのオプションは、CLOUDINARY_URL環境変数を設定することです。.envを使用しているため、ファイルでこれを行うことができますdotenv

CLOUDINARY_URL=cloudinary://api_key:api_secret@cloud_name

2 つ目の方法はcloudinary config、Keystonejs アプリ内で設定を行うことです。

これは、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 構成ページで詳しく説明されていましたが、もう存在しません。

于 2014-10-04T00:53:35.193 に答える
3

何かを追加 -

実際に私にとってうまくいったのは、構成設定部分を

keystone.init 部分。セッターを使用してもうまくいきませんでした。

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

上記のコードは、問題なく動作した唯一のコードです。

于 2015-03-08T10:46:01.017 に答える
1

これが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
于 2016-02-01T03:07:39.667 に答える