Skip to content

Updates necessary for the Heroku deployment #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2a08945
remove node 0.10 pin
berezovskyi May 9, 2019
006f879
update MONGO env config
berezovskyi May 9, 2019
aacb124
update MONGO connection init
berezovskyi May 9, 2019
4547f77
update MONGO db call
berezovskyi May 9, 2019
0b8c8fb
bind to the right port
berezovskyi May 9, 2019
8a1a01f
bind to the right port
berezovskyi May 9, 2019
3a6e50a
update config
berezovskyi May 9, 2019
957f7e5
update config
berezovskyi May 9, 2019
7fe9ebb
update config
berezovskyi May 9, 2019
9a3256a
play with N3 version
berezovskyi May 9, 2019
28478d3
play with N3 version
berezovskyi May 9, 2019
66e04e4
play with N3 version
berezovskyi May 9, 2019
2d8bdd1
remove port config
berezovskyi May 9, 2019
7d2cdde
do not normalise
berezovskyi May 9, 2019
317656f
handle nil uris
berezovskyi May 9, 2019
81eb4bf
handle nil uris
berezovskyi May 9, 2019
dbbbd9b
handle nil uris
berezovskyi May 10, 2019
27b9e47
handle nil uris
berezovskyi May 10, 2019
c34f5f0
handle nil uris
berezovskyi May 10, 2019
4a55c0f
handle nil uris
berezovskyi May 10, 2019
eb1cbd3
fix HTTPS URIs
berezovskyi May 10, 2019
e0958ba
IRI test through isNamedNode
berezovskyi May 10, 2019
a5d08d3
Add a string check function
berezovskyi May 10, 2019
1d8d123
Pass through non-string objects
berezovskyi May 10, 2019
dfb579b
Convert all objects to JSON in the log
berezovskyi May 10, 2019
1c15cf9
Look into 'id' key of the object in the viz
berezovskyi May 10, 2019
d4784ef
Use N3.Util.isNamedNode always
berezovskyi May 10, 2019
d5d0380
Better string detection
berezovskyi May 10, 2019
b55db1b
Update config for localhost
berezovskyi May 10, 2019
0a34b43
Bind to any host
berezovskyi May 10, 2019
f8a8e51
host -> hostname key in the config
berezovskyi May 10, 2019
26edfe5
Use protocol/port from the latest Node
berezovskyi May 10, 2019
61e0685
Update URI handling
berezovskyi May 10, 2019
d701d12
fix URI handling
berezovskyi May 10, 2019
897d1b9
proper protocol handling
berezovskyi May 10, 2019
b3582a5
use new URL API
berezovskyi May 10, 2019
c3e8910
typo
berezovskyi May 10, 2019
b908a4d
undo a bug
berezovskyi May 10, 2019
af75963
fix
berezovskyi May 10, 2019
99b068a
quirks for old/new URL API
berezovskyi May 10, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"scheme": "http",
"host": "localhost",
"protocol": "http",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scheme and host are the w3c names used in https://www.w3.org/Addressing/URL/url-spec.txt. These should be named using standard terms in the config.json file to avoid confusion. scheme is the name of the protocol to use, host is the name of the node to bind to.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made this change so that the JSON keys match the attributes in the https://nodejs.org/docs/latest-v10.x/api/url.html

"bind": "0.0.0.0",
"port": 3000,
"host": "localhost",
"context": "/r",
"mongoURL": "mongodb://localhost:27017/ldp"
}
4 changes: 2 additions & 2 deletions db.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ function ensureIndex() {
}

exports.init = function(env, callback) {
require('mongodb').connect(env.mongoURL, function(err, conn) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have:

	const MongoClient = require('mongodb').MongoClient;
	const client = new MongoClient(env.mongoURL, { useNewUrlParser: true });
	client.connect(function(err, client) {
		if (err) {
			callback(err);
			return;
		}

		db = client.db(env.dbName);
		exports.graphs = graphs();
		console.log("Connected to MongoDB at: "+env.mongoURL);
		ensureIndex();

Here.

require('mongodb').connect(env.mongoURL, { useNewUrlParser: true }, function(err, conn) {
if (err) {
callback(err);
return;
}

db = conn;
db = conn.db();
exports.graphs = graphs();
console.log("Connected to MongoDB at: "+env.mongoURL);
ensureIndex();
Expand Down
49 changes: 29 additions & 20 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ var url = require("url");
var config = require('./config.json');

// the IP address of the Cloud Foundry DEA (Droplet Execution Agent) that hosts this application:
exports.listenHost = (process.env.VCAP_APP_HOST || process.env.OPENSHIFT_NODEJS_IP || config.host);
exports.listenHost = (process.env.VCAP_APP_HOST || process.env.OPENSHIFT_NODEJS_IP || config.bind);

// the port on the DEA for communication with the application:
exports.listenPort = (process.env.VCAP_APP_PORT || process.env.OPENSHIFT_NODEJS_PORT || config.port);
exports.listenPort = (process.env.PORT || process.env.VCAP_APP_PORT || process.env.OPENSHIFT_NODEJS_PORT || config.port);

function addSlash(url) {
if (url.substr(-1) == '/') {
Expand All @@ -37,32 +37,38 @@ function addSlash(url) {
}

function toURL(urlObj) {
if ((urlObj.scheme === 'http' && urlObj.port === 80) ||
(urlObj.scheme === 'https' && urlObj.port === 443)) {
if ((urlObj.protocol === 'http' && urlObj.port === 80) ||
(urlObj.protocol === 'https' && urlObj.port === 443)) {
delete urlObj.port;
}

return url.format(urlObj);
}

// scheme, host, port, and base URI
var appInfo = JSON.parse(process.env.VCAP_APPLICATION || "{}");
if (process.env.LDP_BASE) {
// LDP_BASE env var set
exports.ldpBase = addSlash(process.env.LDP_BASE);
var url = url.parse(exports.ldpBase);
exports.scheme = url.scheme;
exports.host = url.host;
exports.port = url.port;
exports.context = url.pathname;
exports.appBase = toURL({
protocol: exports.scheme,
host: exports.host,
port: exports.port
});
var ldpUrl = new URL(addSlash(process.env.LDP_BASE));
exports.ldpBase = ldpUrl.href;
exports.protocol = ldpUrl.protocol.replace(':', '');
exports.host = ldpUrl.hostname;
if(ldpUrl.port) {
exports.port = ldpUrl.port;
}
else {
if(exports.protocol === 'http') {
exports.port = 80;
} else if (exports.protocol === 'https') {
exports.port = 443;
}
}
exports.context = ldpUrl.pathname;
var baseUrl = new URL(addSlash(process.env.LDP_BASE));
baseUrl.pathname = '';
exports.appBase = baseUrl.href;
} else {
// no LDP_BASE set
exports.scheme = (process.env.VCAP_APP_PORT) ? 'http' :config.scheme;
exports.protocol = (process.env.VCAP_APP_PORT) ? 'http' :config.protocol;
if (appInfo.application_uris) {
exports.host = appInfo.application_uris[0];
} else {
Expand All @@ -76,13 +82,13 @@ if (process.env.LDP_BASE) {
exports.context = addSlash(config.context);

exports.appBase = toURL({
protocol: exports.scheme,
protocol: exports.protocol,
hostname: exports.host,
port: exports.port
});

exports.ldpBase = toURL({
protocol: exports.scheme,
protocol: exports.protocol,
hostname: exports.host,
port: exports.port,
pathname: exports.context
Expand All @@ -96,7 +102,10 @@ if (process.env.VCAP_SERVICES) {
} else {
if (process.env.OPENSHIFT_MONGODB_DB_URL) {
exports.mongoURL = process.env.OPENSHIFT_MONGODB_DB_URL;
} else {
} else if (process.env.MONGODB_URI) {
// Heroku
exports.mongoURL = process.env.MONGODB_URI;
}else {
exports.mongoURL = process.env.MONGO_URL || config.mongoURL;
}
}
4 changes: 2 additions & 2 deletions jsonld.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function jsonldResource(subject) {
}

function jsonldObject(object) {
if (N3.Util.isUri(object) || N3.Util.isBlank(object)) {
if (N3.Util.isNamedNode(object) || N3.Util.isBlank(object)) {
return jsonldResource(object);
}

Expand Down Expand Up @@ -101,7 +101,7 @@ exports.serialize = function(triples, callback) {
}

var object;
if ((N3.Util.isUri(triple.object) || N3.Util.isBlank(triple.object)) && !map[triple.object]) {
if ((N3.Util.isNamedNode(triple.object) || N3.Util.isBlank(triple.object)) && !map[triple.object]) {
object = jsonldResource(triple.object);
}

Expand Down
Loading