Deploying Hexo on Azure.. not sure what i'm missing - node.js

I recently decided to start a small blog for personal use (for now) on Azure. I started digging into the blogging framework Hexo. Now i got the (first) basics under control with starting a Hexo blog locally, but i want to push it to Azure.
I configured a basic web-app with a GIT connection for continuous deployment (https://github.com/lmeijdam/demo-repo). I tried a tutorial with a
server.js file
package.json
.gitignore
Above will result in a working response and installed node_modules... But from there i am really lost about my next steps...
I know you can create a package.json file and viewing my ftp client the package.json is there and also the node_modules folder with the correct modules installed. My package.json;
{
"name": "hexo-site",
"version": "0.0.0",
"private": true,
"hexo": {
"version": "3.1.1"
},
"dependencies": {
"express": "*",
"hexo": "^3.1.0",
"hexo-deployer-git": "0.0.4",
"hexo-generator-archive": "^0.1.2",
"hexo-generator-category": "^0.1.2",
"hexo-generator-index": "^0.1.2",
"hexo-generator-tag": "^0.1.1",
"hexo-renderer-ejs": "^0.1.0",
"hexo-renderer-marked": "^0.2.4",
"hexo-renderer-stylus": "^0.3.0",
"hexo-server": "^0.1.2"
}
}
and i also found out you can deploy a Procfile to the GIT repo which Azure then uses, if you have no default file called server.js (https://github.com/yavorg/azure-node-starter/blob/master/Procfile)
And later a friend came with the tip to edit the procfile to write something like;
web: /node_modules/hexo/bin/hexo server instead of just the web: node server.js
unfortunately this just results in a default blanco webpage... http://lmnodetest1.azurewebsites.net/
Am i doing stuff wrong here or am i forgetting something at the start?

Per my experience, Hexo is a static blog website generator. You can follow these steps below to generate a website at the path "public".
$ hexo init blog
$ cd blog
$ npm install
$ hexo generate
Then, the "public" directory generated, and you can entry into this directory and run the command hexo server to browse http://localhost:4000 to explore your blog.
$ cd public
$ hexo server
For deploying the blog into Azure Website by using Git, you just need to create a local git repo by commanding git init at the "public" dir.
Please refer to the doc https://azure.microsoft.com/en-us/documentation/articles/web-sites-deploy/ to deploy it into Azure.
Best Regards.

Here are the steps that I do to run Hexo blog on Azure: http://the-coderok.azurewebsites.net/2015/09/16/Running-Hexo-blog-on-Azure/

It seems to me that the best part about using hexo is as a static site generator. The hexo server is really meant to give you a nice development environment where you can see your posts right away, but if you're publishing your site you'd wanna serve the statically generated content to remove node from the picture.
Hexo has hexo generate for that and you can get that to work nicely with Azure if you have a custom deployment script.
Here is a repo with 2 commits that you can git push to an empty site and it'll create a working static hexo blog:
First commit is just the result of hexo init blog
Second commit is the custom deployment script. You'd want to copy these 2 files to your own repo.
here is the exact parts that you'd need in your deploy.cmd for hexo.
note that the actual script in the repo has way more lines for proper error handling but this is just the gist of what you need
echo Handling Hexo deployment.
IF NOT DEFINED HEXO_PATH (
echo Setting HEXO_PATH to %HOME%\npm_tools\hexo.cmd
set HEXO_PATH="%HOME%\npm_tools\hexo.cmd"
)
IF NOT EXIST %HEXO_PATH% (
echo Hexo CLI isn't installed. Running 'npm install hexo-cli -g'
mkdir "%HOME%\npm_tools"
npm config set prefix "%HOME%\npm_tools"
npm install -g hexo-cli
)
echo Running 'npm install --production'
npm install --production
echo Running 'hexo generate'
%HEXO_PATH% generate
echo Copying static content to site root
"%KUDU_SYNC_CMD%" -v 50 -f "public" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"

I took a quick look at your site. The issue appears to be that you have a server2.js file but no server.js file. Can you try renaming it in your repo and pushing again? That should at least get you past the first hurdle.

Related

Deploying Vue.js + Express + MongoDB App to Heroku

So I've been at this for two days now and can't figure it out. I'm trying to deploy a Vue front end and express back end app to Heroku.
In my root folder I have a "public" folder which contains the front end and "server" folder for the back end.
In the root directory's package.json, the start script is
"start": "npm run pull && start npm run f && start npm run b",
"pull": "git pull",
"f": "cd ./public && npm run serve",
"b": "cd ./server && npm run dev"
This works perfectly fine for me to run locally, and even works with heroku locally as well using heroku local web but when I try to actually push to heroku using git push heroku main it doesn't even get past the git pull claiming:
fatal: not a git repository (or any parent up to mount point /)
I've tried simply getting rid of the git pull, but that just leads down a rabbit hole of other errors I've been trying to figure out for days and I'm hoping I'm just being dumb and missing something obvious. Any help would be greatly appreciated.
I'm going to try and list some things I've tried here:
Setting the heroku remote repository heroku git:remote -a heroku-name-here
Didn't change anything, pretty sure I already have this correct
Removing the git pull
Led to heroku not recognizing "start" sh: 1: start: not found
Removing the 'start' after git pull
Led to vue-cli-service not being found
Literally separating the back and front end into 2 separate repositories and 2 separate heroku things
This seemed to get the back end functioning, but the front end didn't seem to work. Unfortunately I don't remember exactly why but can try again if it would be helpful
All 3 comments from here: How to solve vue-cli-service: not found proplem on heroku?
I kind of fixed it kind of. Here's what I did
So I went back to the approach of kind of keeping them separate. I started by getting the server up and running.
In Heroku, I added the buildpack: https://github.com/timanovsky/subdir-heroku-buildpack.git BEFORE the heroku/nodejs buildpack to allow me to use a subdirectory rather than the whole repo
In Heroku settings, I added the config var PROJECT_PATH with the value server - In this case, server was the sub-directory immediately under my root
In vue.config.js of my front end, I changed the outputted build path to go INTO my server folder, using outputDir: path.resolve(__dirname, "../server/front-end")
In mongodb, under "Security" in "Network Access" which can be found towards the left in the navigation, I added the IP address 0.0.0.0/0 which I believe basically lets anyone access it. This might not be the most secure but it works.
Finally, this basically merged all my routes together which causes chaos because if I had a front end route /test-route and a back-end route /test-route it would like break which made sense. So I simply changed my index.js back end routes to go to /api/ instead of / so kind of like this
const mutators = require("./routes/mutators");
app.use(router.use("/api/", mutators));
Then at the end of my index.js file, I added
app.route("/*").get(function(req, res) {
res.sendFile(path.join(__dirname + "/front-end/index.html"));
});
so that front end routes like /test-route would then actually go to the site.

Syntax error when start $ heroku open

I am new to Heroku and I am trying to deploy my first app onto Heroku.
I followed instruction, which were:
git init, add and commit my app's source code.
heroku create to create Heroku remote repo for my app.
git push heroku master to push my app's source code to heroku
heroku open
Problem happened when I tried to run heroku open, which was:
$ heroku open
(node:6192) SyntaxError Plugin:
heroku:C:\Users\hauph\AppData\Local\heroku\conf
ig.json: Unexpected string in JSON at position 72 module:
#oclif/config#1.6.33
task: runHook prerun
plugin: heroku
root: C:\Program Files\heroku\client
See more details with DEBUG=*
Image taken from that error
I checked file config.json at the direction as addressed above, and it was:
{
"schema": 1,
"install": "554c101b-d4de-496c-9768-710142ebfb20"
}
"skipAnalytics": false
}
So what did I do wrong here?
I would be grateful for any help.
Thank you very much!
I had the same problem. Not sure why it ends up corrupted, but the config.json should look like the following (get rid of the curly brace before skipAnalytics):
{
"schema": 1,
"install": "3265b92a-27f4-4adb-9c07-75d9213f0000",
"skipAnalytics": false
}
Your config.json contains invalid JSON (note the two closing brackets). Reinstall the Heroku CLI, and you should be in good shape.
I tried reinstalling but didn't work, just add curly braces in the config.json file.
{
}
Works perfectly now.
I had the same error when I tried to build on heroku as like below
(node:1179857) SyntaxError Plugin: heroku: /home/{...}/.local/share/heroku/config.json: Unexpected end of JSON input
module: #oclif/config#1.18.3
task: runHook prerun
plugin: heroku
root: /snap/heroku/4085
See more details with DEBUG=*
set git remote heroku to https://git.heroku.com/{...}.git
So I opened the config.json file from this path /home/{...}/.local/share/heroku/config.json and added blank curly braces
{
}
Then I run the command heroku git:remote -a {your project name} to set heroku git remote
Finally checked the config.json file and added valid json value automatically like this screenshot:
{
"schema": 1,
"install": "19975845-fr45-hfgt6-iu78-c27hgy243c46d",
"skipAnalytics": false
}
Finally set remote successfully. I hope it will make developers easier to deploy on heroku if this type of error comes.
USAGE
$ heroku apps:open [PATH]
OPTIONS
-a, --app=app (required) app to run command against
-r, --remote=remote git remote of app to use
EXAMPLES
$ heroku open -a myapp
# opens https://myapp.herokuapp.com
$ heroku open -a myapp /foo
# opens https://myapp.herokuapp.com/foo
Please visit heroku cli commands documentation here https://devcenter.heroku.com/articles/heroku-cli-commands

Running blockchain-wallet-service on a Heroku worker

I'm trying to deploy my Django app on Heroku, that makes use of the Blockchain.info API V2 (https://github.com/blockchain/service-my-wallet-v3) and thus needs to run blockchain-wallet-service in the background, which in turn needs Node.js and npm installed.
On localhost, I have used this API successfully by running the service on my own machine, but I'm having trouble deploying to Heroku. Firstly, I assume I will need to run the service on a separate dyno, and that I will need node and npm installed on my instance.
Can someone tell me how to achieve this? I'm new to more advanced features of Heroku, I've tried to use the nodejs buildpack but I doubt this is the correct way. There is also this: https://elements.heroku.com/buttons/kmhouk/service-my-wallet-v3 which I've deployed as a separate app but I've failed to merge it in some way to my Django app.
Any help is much appreciated!
I had this exact same issue, bro, and i finally got some light in the end of the tunnel.
I've cloned the https://github.com/blockchain/service-my-wallet-v3 repository and deployed it to heroku and made some changes on "package.json" file. The problem is that (in heroku) you need to declare the dependencies on package file. I've added these lines:
"dependencies": {
"blockchain-wallet-service": "~0.22.4",
}
and a script to test in the deploy:
"scripts": {
"postinstall": "blockchain-wallet-service -V"
}
Also, by cloning this repository, i needed to add this line too:
"license" : "(ISC OR GPL-3.0)",
hope it works for you

Gulp deploy dist folder of Node app to Heroku

I'm reasonably new to node, git, github and Heroku and I'm struggling to work out the best way of sending my application to Heroku without cluttering up the repo with my compiled, minified app and without doing too much in Heroku.
My node.js project looks a bit like this:
- client
... code
- server
... code
- node_modules
- package.json
- gulpfile.js
- dist
- client
- server
Everything apart from node_modules and dist goes into github.
The gulpfile compiles, minifies and concatenates everything ready for release in dist.
How do I push just the dist folder to Heroku, without also putting it into github? What is best practice? I'd rather not send my gulpfile to Heroku as it means moving the devDependencies in package.json and using a post update script, as it ties the project to Heroku more than I'd like.
Reasons for not using post hook are summed up well in these two posts: https://stackoverflow.com/a/15050864/344022 & https://stackoverflow.com/a/21056644/344022, unfortunately they don't provide an easy to understand alternative.
Heroku now has a static buildpack in development to handle this (see https://github.com/heroku/heroku-buildpack-static)
Create a static.json file to use the files from dist/ with .html suffix and to re-route all calls back to the SPA
{
"root": "dist/",
"clean_urls": true,
"routes": {
"/**": "index.html"
}
}
Extend package.json scripts to ensure dist/ directory is built, for example
"scripts": {
...
"heroku-postbuild": "gulp"
}
So that dev dependencies from package.json get installed
heroku config:set NPM_CONFIG_PRODUCTION=false --app
Multiple build packs so you can build and deploy
heroku buildpacks:add heroku/nodejs --app <app_name>
heroku buildpacks:add https://github.com/heroku/heroku-buildpack-static.git --app <app_name>
Your procfile can be empty in this case.
I had the same problem of pushing only the dist folder to heroku app, Right now I am using a different approach, not sure the idle one, but it works for me. I created a deploy file and added the below code
import {spawnSync} from 'child_process';
function deploy(){
options = {
cwd: path.resolve(__dirname, './dist')
};
//push dist folder to deploy repo
console.log('Initialising Repository');
spawnSync('git',['init'],options);
console.log('Adding remote url');
spawnSync('git',['remote','add', remote.name, remote.gitPath],options)
console.log('Add all files');
spawnSync('git',['add','.','--all'],options)
console.log(`Commit with v${version}`);
spawnSync('git', ['commit','-m',`v${version}`], options)
console.log('Push the changes to repo');
spawnSync('git', ['push', '-f', remote.name, 'master'],options)
}
kept repo iformation in package.json and read here, I am running this after a webpack build task. So this will push my new build to heroku. Even if the .git inside dist gets deleted it will take care of it.
Go on, set up a post hook on heroku which builds you app and copies the files to where they'll be served. This is fairly normal practice, and once it's set up all you need to do is a git push to deploy your app, which is really rather handy. The alternative is to have a separate repository which you manually copy the files to and push from, but that doesn't seem as slick to me, greater chance of human error by messing up the dependencies, or forgetting to delete generated files which are no longer needed etc.

How to deploy a MeteorJS app to Windows Azure? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How does one deploy a production MeteorJS app to Windows Azure?
Yes it is. See http://www.meteorpedia.com/read/Deploying_to_a_PaaS
In most cases this is as simple as using "meteor bundle",
demeteorizer, and then uploading the resulting files with your PaaS
provider's CLI deploy tool.
Demeteorizer wraps and extends Meteor’s bundle command by creating
something that more closely resembles a standard looking Node.js
application, complete with a package.json file for dependency
management.
$ cd /my/meteor/app
$ demeteorizer -o /my/node/app
$ cd /my/node/app
$ npm install
$ export MONGO_URL='mongodb://user:password#host:port/databasename?autoReconnect=true&connectTimeout=60000'
$ export PORT=8080
$ forever start main.js
Forever keeps your app running after a disconnect or crash, but not a reboot unless you manually add a boot entry.
The whole deploy is much easier using Meteor Up instead. Or maybe mups, though that doesn't even have updated docs.
To run a Meteor app in an Azure web app:
Azure Web App
Python 2.7
Websockets ON (optional)
WEBSITE_NODE_DEFAULT_VERSION 0.10.32 (default)
ROOT_URL http://webapp.azurewebsites.net
MONGO_URL mongodb://username:password#instance.mongolab.com:36648/dbname (For advanced apps. Request log should say if you need it.)
Dev Machine
Install Visual Studio Community 2015
Install Node 0.12.6
Install Meteor MSI
app> demeteorizer -o ..\app-dem
app-dem\programs\server\packages\webapp.js change .PORT line to "var localPort = process.env.PORT"
app-dem\package.json change "node": "0.10.36" to "node": "0.12.6"
app-dem> npm install
app-dem> git init
app-dem> git add -A .
app-dem> git commit -m "version 1.0 demeteorized Meteor + tweaks"
app-dem> git remote add azure https://username#webapp-slot.scm.azurewebsites.net:443/webapp.git
app-dem> git config http.postBuffer 52428800
app-dem> git push azure master
Instead of demeteorizer -o, perhaps you could use meteor build and create a package.json in the output root:
{
"name": "App name",
"version": "0.0.1",
"main": "main.js",
"scripts": {
"start": "node main.js"
},
"engines": {
"node": "0.12.6"
}
}
If bcrypt doesn't compile, make sure to use a more recent version:
"dependencies": {
"bcrypt": "https://registry.npmjs.org/bcrypt/-/bcrypt-0.8.4.tgz"
}
Before starting make sure your have install'd a 32 bit version of nodejs and have run "npm -g install fibers" on your windows build machine. Default nodejs on azure is running 32 bit only!
Note: this will not work if you'r using for example the spiderable package which relays on PhantomJS. PhantomJS can not be executed in a webapp on azure?
In your project "meteor build ..\buildOut" and extract the .tar.gz file located in "..\buildOut".
Place/create in "..\buildOut\bundle" a "package.json" containing:
{
"name": "AppName",
"version": "0.0.1",
"main": "main.js",
"scripts": {
"start": "node main.js"
},
"engines": {
"node": "0.12.6"
}
}
Note: Make sure "name" doesn't contain spaces, the deploy on azure will fail.
On your favorite shell, goto "..\buildOut\bundle\programs\server" and run "npm install". This will pre download all the requirements and build them.
Now open the file "..\buildOut\bundle\programs\server\packages\webapp.js" and search for "process.env.PORT".
it looks like this:
var localPort = parseInt(process.env.PORT) || 0;
alter this line into:
var localPort = process.env.PORT || 0;
This is needed so your meteor project can accept a named socket as soon as it runs in node. The function "parseInt" will not let a string go thru, the named socket is a string located in your webapp's environment. This my be done for a reason, a warning here! Now save this change an we are almost done...
Solve the bcrypt issue: Download this file and extract it somewhere: https://registry.npmjs.org/bcrypt/-/bcrypt-0.8.4.tgz
Extract it.
Now replace the files located: "..\buildOut\bundle\programs\server\npm\npm-bcrypt\node_modules\bcrypt*"
with the directory's and file's located somewhere: ".\bcrypt-0.8.4\package*"
Now go on the shell in the directory "..\buildOut\bundle\programs\server\npm\npm-bcrypt\node_modules\bcrypt\" and make sure you remove the "node_modules" directory. If the node_modules directory is not removed npm will not build the package for some reason.
Run on the shell "npm install".
Make sure you set the "Environment" variables: "MONGO_URL" and "ROOT_URL" in the portal for you webapp.
If everything worked without an error, you can deploy your app to the git repository on the deployment slot for your webapp. Go to "..\buildOut\bundle" and commit the files there to the deployment slot's repository. This will course the deploy on the deployment slot and create the needed iis configuration file(s).
Now wait a little and your app should fire after some time... Your app should be running and you can access it on the *.azuresites.net
Thanks to all that made this possible.

Resources