Running Ghost in IIS with Iisnode - node.js

I have a problem getting iisnode and ghost to play together.
I can run the samples supplied with iisnode fine and I can get ghost up and running fine through the node command line. I have followed every blog post written online I can find to get them set up together. The frustrating thing is the blogs make this process look extremely straightforward.
From looking at "ETW" logs it looks like iisnode cannot communicate with the node process using named pipes ("iisnode scheduled a retry of a named pipe connection to the node.exe process" x20+), and then the node process terminates.
The problem may not lie with ghost, tbh I cannot work out what to do or which part to tweak next. My best guess at this point is some sort of permissions issue, but I've spent hours setting permissions all over my development machine to no avail.
If it helps, the error message I get back in the browser is: ERROR: (Code: EACCES) There was an error starting your server.

To answer my own question, I examined the Process Monitor output for node.exe, line by line to see if I could see anything strange. I'm no expert at analysing the output from Process Monitor and there are a tonne of "Buffer Overflow" messages and other things that could be errors, but then I happened to stumble upon the following line:
Node.exe CreatePipe \MyProjects\WebsiteName\process.env.port\ INVALIDDEVICEREQUEST
Invalid device?
Then the penny finally dropped. In config.js you do not want to set your port to 'process.env.port' (as is suggested in the config.js file itself as a comment) you want to set the port to process.env.port.
No quotes.

Just to clarify what ruethewhirl551 said, here is an excerpt from my working "config.js":
config = {
production: {
url: 'http://my-blog.com',
mail: {
transport: 'SMTP',
options: {
service: 'Mailgun',
auth: {
user: 'postmaster#my-blog.com',
pass: '9ed512da012cd454376947365xd71793'
}
}
},
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost.db')
},
debug: false
},
server: {
host: '127.0.0.1',
port: process.env.PORT // <-- HERE
}
},
// ...
Please notice the line port: process.env.PORT at the bottom.
You can also search for "iisnode" through the "config.example.js" file for more information.

Related

Server runs locally but crashes on Heroku

I deployed my server on Heroku but when I make any requests it returns a "500 Internal Server" error. It runs fine locally though. Could anyone help figure out what's going on?
When I check my logs this is what I'm getting.
2021-06-08T18:43:09.715406+00:00 app[web.1]: error: no pg_hba.conf entry for host "3.90.138.215", user "detmvsbueicsez", database "da9nlve42hcp91", SSL off
Repo Link: https://github.com/zcason/Restaurant-Review-Server
Live App: https://restaurant-review-phi.vercel.app/
As mentioned here on Heroku help, this indicate that there was a failed authentication attempt to the database, so the connection couldn't be established. This can happen because of different reasons.
In your case i suspect it's something related to not using ssl.
So after taking a look on the code provided in the github repo i noticed you are using knex and getting the connection string from .env
Try this :
Just add this ?ssl=true and append it to the end of DATABASE_URL in your .env file.
Edit your server.js (i didn't take a good look at the code so you need to add this ssl: { rejectUnauthorized: false } in your connection config) :
const db = knex({
client: 'pg',
connection: {
connectionString: DATABASE_URL,
ssl: { rejectUnauthorized: false }
}
});
Also make sure you're using the wright user and password and database name etc
OR Alternatively :
Run this command heroku config:set PGSSLMODE=no-verify in terminal to omit the ssl configuration object and set PGSSLMODE to no-verify

Is there a way to expose debug lines during scp2 upload operation in nodejs?

I am using this package in a nodejs app: https://www.npmjs.com/package/scp2 and it is calling upload(src, dest) to a unix server. It is not connecting to the unix server and the only error I see is Exit code 255 while establishing SFTP session. I realize it is not connecting due to something on the Unix servers OpenSSL package changing but since its rollback, it is still not working as it was before.
Is there a way to display the debug lines for scp2.upload()? I am stepping through the scp2 package in vscode debug mode but not finding anything.
I added this in the scp2 configs: debug: console.log as such:
this.sshCreds = {
host: this.host,
username: this.username,
password: this.password,
debug: console.log,
};
this.sshClient = new SshClient(this.sshCreds);

Running w/ intern-runner: nothing outputted to terminal, no code coverage data

I am launching my Intern-based tests through the intern-runner script, like this:
<full_path>\intern\.bin\intern-runner config=unittest/intern
My unittest\intern.js configuration file contains the following:
define({
reporters: [ "junit", "console", "lcovhtml", "runner" ],
excludeInstrumentation: /(?:dojo|intern|istanbul|reporters|unittest)(?:\\|\/)/,
suites: [ "unittest/all_intern.js" ],
forDebug: console.log("Customized intern config for test runner loaded successfully!"),
loader: {
packages: [
{ name: 'resources', location: 'abc/resources' },
{ name: 'stats', location: 'abc/resources/stats' },
{ name: 'nls', location: 'abc/nls' },
{ name: 'widgets', location: 'abc/widgets' },
{ name: 'views', location: 'abc/views' },
]
},
useLoader: {
'host-browser': 'node_modules/dojo/dojo.js'
},
tunnel: 'NullTunnel',
useSauceConnect: false,
webdriver: {
host: 'localhost',
port: 4444
},
proxyUrl: "http://localhost:8010/",
environments: [
{
browserName: 'chrome'
}
]
});
Output to the terminal/command window looks hopeful:
Customized intern config for test runner loaded successfully!
Listening on 0.0.0.0:9000
Starting tunnel...
Initialised chrome 40.0.2214.111 on XP
And the Chrome browser is indeed launched, and I see my unittests running and passing in the browser contents. However, control never goes back to the terminal/command window--I don't see anything like "634/634 tests pass" or whatever, and I have to Ctrl+C to kill the intern-runner process. And of course, no code coverage files are generated. Is this due perhaps to my file structure? The Intern files are in a completely separate directory from these unit tests--I am not invoking intern-runner from a common parent directory for both Intern libraries and unit test files (and the product files they are testing).
I can create a diagram to illustrate the file/directory structure, if that is important. Note that I did change the Intern structure a bit, like:
<Dir_123>\intern\intern-2.2.2\bin\intern-runner.js
<Dir_123>\intern\intern-2.2.2\lib\<all_the_usual>
<Dir_123>\intern\intern-2.2.2\node_modules\<all_the_usual>
<Dir_123>\intern\.bin\intern-runner.cmd
i.e., what I had changed was to insert an extra "intern-2.2.2" directory after "intern", and the ".bin" directory containing intern-runner.cmd is a peer of "intern-2.2.2". Hope this is not confusing. :(
And note that the "proxyUrl" config property represents the URL that the unittest files and product files are available from the web server. Am I doing this right, by configuring the proxyUrl for this purpose? If I omit it, nothing runs because the default used is localhost:9000. I see in the "Configuring Intern" article on Github that proxyUrl is "the URL to the instrumentation proxy," but I don't really understand what that means.
It looks like you're making pretty good progress. Your directory structure is a bit non-standard (any particular reason for that?), but that shouldn't be a show-stopper. The problem you're seeing is probably due to a proxy misconfiguration. Intern is loading the test client and your unit tests, but the code in the browser is unable to communicate test results back to Intern.
As you mentioned, the proxyUrl parameter is the URL at which Intern's instrumenting proxy can be found. The "instrumenting proxy" is basically just an HTTP server than Intern runs to serve test files and to receive information from browsers under test. (It also instruments JS files as it serves them to gather code coverage data, hence the "instrumenting" part of the name.) By default, it's at localhost:9000. That means a browser under test running on localhost can GET or POST to localhost:9000 to talk to Intern.
You can also run Intern behind another server, like nginx, and have that server proxy requests to Intern. In that case, you need to 1) set Intern's proxyUrl to the address of the proxying server, and 2) setup proxying rules in the server to pass requests back to Intern at localhost:9000.
Intern also has a proxyPort parameter to control the port the instrumenting proxy serves on. The proxy listens at localhost:<proxyPort>, where proxyPort defaults to 9000. If tests are talking to Intern's proxy directly (with no intermediate nginx or Apache or anything), proxyPort will be the same as the port in proxyUrl. If an intermediate server is being used, the two can have different values.
When intern-runner runs unit tests, it tells the test browser to GET <proxyUrl>/client.html?config=.... Since you have some external server running and you've set proxyUrl to that server's address, that server will serve client.html and the other relevant Intern files, allowing the unit tests to run. However, when the unit tests are finished and the browser attempts to communicate this back to Intern at proxyUrl, it's going to fail unless you've configured the external server to proxy requests back to localhost:<proxyPort>.

How to actually run mozilla openbadges

I'm following this tutorial here.
https://github.com/mozilla/openbadges-badgekit/wiki/BadgeKit-Self-Hosting-Guide#badgekit-api-configuration
It says, when you run the API use this command source env_local
The problem is, I'm new to node and not really sure how I run the API. I've downloaded all the stuff, installed node, and got a simple hello world program working with node. I just don't know how I actually run the API. I thought I had to run the procfile, but when I do node procfile I get an error saying cannot find module badegkit\badgekit-api\start
As a hacky ass solution, I figured this out. I tried setting PATH in environment variables to env_local, as well as doing SET path = env_local in the command window and neither worked. However, if you browse to the badgekit api folder then app then lib, there's a db.js file in there.
Here's what I did, their stuff is commented out.
var options = {
driver: 'mysql',
// host: process.env.DB_HOST,
// user: process.env.DB_USER,
// password: process.env.DB_PASSWORD,
// database: process.env.DB_NAME,
host: "127.0.0.1",
user: "username",
password: "password",
database: "dbname",
}
Just put in your mysql creds and then you can run the db migrate. Obviously this isn't ideal as anywhere else that uses env is still going to be screwy, but it got me to step 2.
2014-09-29 Edit
For all those curious, as of right now, node isn't really supported on windows per se. I ran into so many issues with python and gyp, that I ended up just spinning up a linux box in hyper v and hosting it there.
The idea behind that command is to load the environment variables setup in env_local. By deafult, they are set up as a few export commands, which should put the key=value pairs into your running environment.
I actually removed the export strings and stored them as .env_dev, so a file with:
DB_HOST=localhost
DB_NAME=badgekitapi
...etc...
And the command I used to run things was: nf start -e .env_dev
With the API running, and able to store badges, you can now follow the tutorials to run openbadges-badgekit - so you can actually make and issue some badges ; )
Good luck!

Grunt Connect server ignoring port and not opening browser

Trying to get grunt-connect setup.
What I want is to start a server (either localhost or an IP), the browser to open at that url and ideally this to livereload when a CSS, HTML or JS file is changed. But we can come to that later.
This is what I have in the gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
includesPath: "includes",
connect: {
test: {
port: 9001,
hostname: '0.0.0.0',
base: '',
open: true
}
}
});
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.registerTask('default', ['connect:test']);
grunt.registerTask('server', ['connect:test']);
};
this is the dependency in the package.json
"grunt-contrib-connect": "~0.8.0"
When I run either grunt or grunt server the Terminal window says
Started connect web server on http: //0.0.0.0:8000
It doesn't open a browser. If I go to that address in the browser, there is no page there.
What do you reckon?
So it seems I was missing the options object! What a stupid, Friday afternoon mistake that was. Frustrating that it didn't error though, I assume it has default settings it uses, which would explain why it used it's on port?
This code did the trick, thanks for your help Dave McNally
connect: {
server: {
options: {
keepalive: true,
port: 4000,
base: '.',
open: true
}
}
}
You’ll want a value in the base parameter, the default '.' will do if source is in same root directory and as mentioned, you don't need to specify hostname when using the default. Also, check ports, as you're specifying one in the task but then opening another in the given address?

Resources