$ heroku login
$ sudo npm install -g generator-kraken
$ yo kraken
and interactively answer the questions of the generator:, "" "`. / _ _ \ | (@) (@) | Release the Kraken! ) __ ( /, ')) ((`. \ (((()))) `\`) ('/' [?] Application name: Kraken-Sockets [?] Description: A test kraken application with socks.js [?] Author: <your name> [?] Use RequireJS? (Y / n) n
/config json /controllers /lib /locales /models /public Web-, /public/templates /tests - index.js ()
npm start
command and at localhost: 8000 we can admire a working Kraken.js application. Well, now it's time to pour it on Heroku. But first you need to bring the application into compliance with the requirements . We already have the package.json
file, now we need to create a Procfile
file with the following content: web: node index.js
PORT
environment variable. We cannot do this through json-configs. Especially for these cases, Kraken.js provides a software configuration mechanism. The method responsible for the software configuration is in the index.js
file. We must give it the following form: app.configure = function configure(nconf, next) { // Async method run on startup. nconf.set('port', Number(process.env.PORT || 5000)); next(null); };
$ git init $ git add . $ git commit -m "init"
$ heroku create kraken-test-socksjs
$ git push heroku master
$ heroku logs
) and google. And everything turned out to be very simple. Heroku, for some reason, loses some dependencies of the second level (dependencies of dependencies of the application - it sounds horrible, I will give an example: in our case it loses the formidable
module, on which the kraken-js
module depends). And he also doesn’t perform grunt tasks for resource preparation (compiling less, templates, etc.).package.json
file, we transfer all devDependencies
to dependencies
and add the "grunt-cli": "~0.1.13"
module to dependencies
"grunt-cli": "~0.1.13"
. This will allow us to call grunt manually during the application deployment. After all changes, the package.json
file should look like this: { "name": "kraken-sockets", "version": "0.1.0", "description": "", "author": "Your Name", "main": "index.js", "scripts": { "test": "grunt test", "start": "node index.js", "postinstall": "./node_modules/grunt-cli/bin/grunt build --force" }, "engines": { "node": ">=0.10.0" }, "dependencies": { "kraken-js": "~0.7.0", "express": "~3.4.4", "adaro": "~0.1.x", "nconf": "~0.6.8", "less": "~1.6.1", "dustjs-linkedin": "~2.0.3", "dustjs-helpers": "~1.1.1", "makara": "~0.3.0", "mocha": "~1.17.0", "supertest": "~0.8.2", "grunt": "~0.4.1", "grunt-cli": "~0.1.13", "grunt-contrib-less": "~0.9.0", "grunt-dustjs": "~1.2.0", "grunt-contrib-clean": "~0.5.0", "grunt-contrib-jshint": "~0.6.4", "grunt-mocha-cli": "~1.5.0", "grunt-copy-to": "0.0.10" }, "devDependencies": { } }
"postinstall"
script, which is just preparing application resources. We coped with the problem of resources, and what to do with the missing modules? This is apparently a bug of the new module caching system Heroku. I'll write a ticket to them the other day, but for now I cope with the help of the heroku-repo plugin. Just before each “push” release, I clean the modules cache with the command: $ heroku repo:purge_cache -a kraken-test-socksjs
kraken.create(app).listen(function (err) { if (err) { console.error(err.stack); } });
var k = kraken.create(app); k.listen(function (err) { if (err) { console.error(err.stack); } else { var http = k.app.get('kraken:server'); var sockjs_opts = {sockjs_url: 'http://cdn.sockjs.org/sockjs-0.3.min.js'}; var sockjs_echo = sockjs.createServer(sockjs_opts); sockjs_echo.on('connection', function(conn) { hub.sockjs_pool.push(conn); conn.on('data', function(message) { hub.sockjs_pool.forEach(function(con) { con.write(message); }); }); }); sockjs_echo.installHandlers(http, {prefix:'/echo'}); } });
Source: https://habr.com/ru/post/213199/
All Articles