2014-10-03 46 views
3

我是新來的重點,我試圖部署一個簡單的網站模板,以技術來熟悉自己,我已經下載了所有的necassary模塊,並創建了所有的一個keystone.js文件和文件的package.json依賴。然而,當我試圖在終端,我得到運行keystone.js如下:無效Cloudinary Configuartion

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用於安裝,以確保它被安裝在系統中,但它顯然可以」找到配置。我假設有一個簡單的解決方案,這和我只需把我的configuartion字段代碼的正確的地方,但我似乎無法找到任何指示在何處插入我的賬戶細節。任何幫助將不勝感激,請讓我知道,如果我已經省略了任何重要的代碼。

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" 
} 

回答

4

有,你可以在你的KeystoneJS應用配置Cloudinary多種方式。

一種選擇是設置CLOUDINARY_URL環境變量。您可以在.env文件,做到這一點,因爲你使用dotenv

CLOUDINARY_URL=cloudinary://api_key:[email protected]_name 

第二種方法是在您的Keystonejs應用中設置cloudinary config設置。

你可以做到這一點無論是在您的keystone.init()

keystone.init({ 
    ... 
    'cloudinary config': 'cloudinary://api_key:[email protected]_name', 
    ... 
}); 

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

keystone.set('cloudinary config', 'cloudinary://api_key:[email protected]_name'); 

這些都在KeystonsJS Configuration頁面上詳細說明。

+0

我這樣做,但在重點管理/ gallery它說'找不到畫廊。 ' – Anenth 2015-12-28 01:05:33

+0

我假設你用你自己的Cloudinary帳戶。如果您從未創建/上傳任何畫廊,則管理員應該說「找不到畫廊」。創建一個畫廊並上傳一些照片。 – JME 2015-12-28 01:32:52

+0

默認情況下,cloudinary會提供一張照片!我也從keystonejs提供的例子中嘗試了cloudinary密鑰。它仍然顯示相同的信息 – Anenth 2015-12-28 01:55:53

2

添加的東西 -

那麼究竟是什麼工作對我來說,當我放置在配置在

keystone.init部分設置部分。使用setters不適合我。

keystone.init({ 
    ... 
    'cloudinary config': 'cloudinary://api_key:[email protected]_name', 
    ... 
}); 

上面的代碼是唯一一個完美無缺的工作。

+1

有一個類似的問題,只要我把setters移動到init的上面就會工作。 – Yousef 2015-04-05 19:30:06

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:[email protected]_name 
$ heroku config:set NODE_ENV=production 
$ heroku config:set COOKIE_SECRET=YOUR_COOKIE_STRING