2013-05-08 57 views
1

我想知道是否可以運行grunt-contrib-connect命令以便爲Heroku提供靜態文件。如何在Heroku上運行`grunt connect`進程

我咕嚕文件看起來像這樣:

module.exports = function(grunt) { 

    // Project configuration. 
    grunt.initConfig({ 
    pkg: grunt.file.readJSON('package.json'), 
    connect: { 
     server: { 
     options: { 
      port: process.env.PORT || 5000, 
      base: 'www', 
      keepalive: true 
     } 
     } 
    } 
    }); 

    grunt.loadNpmTasks('grunt-contrib-connect'); 

    // Default task(s). 
    grunt.registerTask('default', ['connect']);  
}; 

我Procfile看起來是這樣的:

web: grunt 

我的package.json看起來是這樣的:

{ 
    "name": "herokoloco", 
    "version": "0.1.1", 
    "scripts": { 
     "postinstall": "bower install" 
    }, 
    "dependencies": { 
     "grunt": "^0.4.5", 
     "grunt-cli": "^0.1.13", 
     "grunt-contrib-connect": "^0.8.0", 
     "bower": "~1.3.9" 
    }, 
    "engines": { 
     "node": "0.10.x" 
    } 
} 

我的文件結構如下像這樣:

> node_modules 
v www 
    index.html 
bower.json 
Gruntfile.js 
package.json 
Procfile 

它使用Heroku的「工頭啓動網站」在本地完美工作,但在Heroku上無法使用。我剛剛得到這個錯誤在我的日誌:

2014-10-08T21:19:23.620448 + 00:00的Heroku [路由器]:在=錯誤代碼= H14 DESC = 「沒有Web進程中運行」 的方法= GET path =「/」 host = shielded-waters-3266.herokuapp.com request_id = 4d669be2-a362-4968-8349-b83b8ad0e2f6 fwd =「198.245.95.126」 dyno = connect = service = status = 503 bytes =

回答

0

通過設置在Procfile中啓動服務器的命令,您可以讓Heroku在完成安裝後運行您想要的任何命令。所以,像這樣:

web: ./node_modules/grunt/.bin/grunt my-grunt-command ; node app.js 

應該工作。

+0

完全瞭解你,但我嘗試過並沒有工作。我不想要的是使用nodejs服務器,我想在'Procfile'中的'web'任務上運行'grunt connect',但它不起作用。 – kevinwolf 2013-05-13 01:41:52

+0

爲了完成這項工作,您可能需要獲取PORT環境變量並找出如何將其添加爲grunt-contrib-connect的選項。 – dankohn 2013-05-13 03:18:35

+0

我已經這樣做了,在'grunt-contrib-connect'選項中我已經把'port:process.env.PORT || 3000',並在Heroku日誌中說Heroku分配了端口,但仍然沒有工作。 – kevinwolf 2013-05-13 05:19:15

0

請確保您有所有包的配置(包括grunt-cli)中列出的呼嚕聲的依賴,確保你刪除連接配置的hostname部分,使用過程端口..即「端口:process.env.PORT | | 5000「連接配置。這對我行得通。

1

它一旦我真的設置了一些dynos的工作。爲此,我從我的Heroku項目的終端發出以下命令:

heroku ps:scale web=1 
+1

這意味着你不能免費咕嚕。 https://devcenter.heroku.com/articles/dyno-size – 2014-10-11 15:18:49

相關問題