403 error when deploying a Node.js app on Heroku - javascript

Earlier, I was getting the following error (from the Chrome console) when trying to open a Node.js app using Heroku:
Refused to load the image 'https://browser-rpg-app.herokuapp.com/favicon.ico' because it violates the following Content Security Policy directive: "default-src 'none'". Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.
This was accompanied by a 403. I managed to fix it by adding this line:
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js 'unsafe-inline'">
Now the first error is gone, but I'm still getting a 403. I can run the app flawlessly on heroku local web, but not when I actually deploy. Here's what the log says:
2019-12-02T22:41:29.000000+00:00 app[api]: Build succeeded
2019-12-02T22:41:32.617542+00:00 heroku[web.1]: Starting process with command `node app.js`
2019-12-02T22:41:36.786903+00:00 heroku[web.1]: State changed from starting to up
2019-12-02T22:42:00.484013+00:00 app[web.1]: ForbiddenError: Forbidden
2019-12-02T22:42:00.484062+00:00 app[web.1]: at SendStream.error (/app/node_modules/send/index.js:270:31)
2019-12-02T22:42:00.484066+00:00 app[web.1]: at SendStream.pipe (/app/node_modules/send/index.js:553:12)
2019-12-02T22:42:00.484068+00:00 app[web.1]: at sendfile (/app/node_modules/express/lib/response.js:1103:8)
2019-12-02T22:42:00.484071+00:00 app[web.1]: at ServerResponse.sendFile (/app/node_modules/express/lib/response.js:433:3)
2019-12-02T22:42:00.484074+00:00 app[web.1]: at index (/app/routes/index.js:9:9)
2019-12-02T22:42:00.484077+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2019-12-02T22:42:00.484079+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/route.js:137:13)
2019-12-02T22:42:00.484081+00:00 app[web.1]: at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
2019-12-02T22:42:00.484083+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2019-12-02T22:42:00.484085+00:00 app[web.1]: at /app/node_modules/express/lib/router/index.js:281:22
2019-12-02T22:42:00.482239+00:00 heroku[router]: at=info method=GET path="/" host=browser-rpg-app.herokuapp.com request_id=845c8d30-4ca7-44f4-ab69-ae312e722b1b fwd="68.174.27.246" dyno=web.1 connect=1ms service=21ms status=403 bytes=380 protocol=https
As you can see, there's no helpful message or explanation, it just says forbidden. I really have no clue what the problem could be, but here's a bunch of important/relevant files:
app.js:
const express = require("express");
const configRoutes = require("./routes");
const static = express.static(__dirname + '/public');
const app = express();
app.use("/public", static);
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const cookieParser = require("cookie-parser");
app.use(cookieParser());
configRoutes(app);
app.listen(process.env.PORT || 3000, () => {
console.log("The application is running on http://localhost:3000");
if (process && process.send) process.send({done: true});
});
package.json:
{
"name": "browserrpg",
"version": "1.0.0",
"description": "",
"main": "app.js",
"engines": {
"node": "10.16.3"
},
"dependencies": {
"angular": "^1.7.2",
"angular-route": "^1.7.2",
"body-parser": "^1.18.3",
"cookie-parser": "^1.4.3",
"express": "^4.16.3",
"mongodb": "^3.1.1",
"npm": "^6.2.0",
"uuid": "^3.3.2"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
"repository": {
"type": "git",
"url": (git url here, removed for privacy)
},
"author": "",
"license": "ISC",
}
Procfile:
web: node app.js
In case it's relevant, here's the "/" route that Heroku calls:
const index = (req, res) => {
res.sendFile(path.join(__dirname, "..\\public\\html", "index.html"));
return;
}
And here's the constructor that sets up all the routes:
const constructorMethod = app => {
app.get("/", index);
app.get("/game", gameGet);
app.post("/game", gamePost);
app.use("*", (req, res) => {
res.status(404).json({ error: "Not found" });
});
};
Here's my file structure as well:
BrowserRPG
│ README.md
│ Procfile
| app.js
| mongoCollections.js
| mongoConnection.js
| package.json
| settings.json
│
└───data
│ enemydata.js
│ gamecalc.js
| gamedata.js
| index.js
│
│
└───public
│
└───css
| main.css
|
└───html
| game.html
| index.html
|
└───js
| angular.js
| angularActiveGame.js
|
└───routes
| index.js
I'm also using a mongodb database, but I don't think that's causing the problem, considering that I haven't even attempted to connect it to Heroku yet, and you don't need to have a db running to get to the first page of the app. Is there something here that might be causing the error? Thanks.

So I finally figured it out, the solution was actually annoyingly simple. In my "/" GET route, the path contains a .., which was being viewed as malicious, and therefore rejected. I changed it to this:
res.sendFile(path.join(appRoot, "public/html", "index.html"));
appRoot is a global variable that points to the root directory of the application. Hopefully this helps someone who may be having a similar issue.

Related

Heroku Error. Cannot find module 'Mongoose'

For some odd reason (i have been deployed on Heroku for around 1.5 years) my instance decided to throw a weird error regarding not finding 'mongoose' after attempting to deploy again. Everything works on my local server and my .gitignore file ignores Node Modules. This is a React.js app with Expressjs and Mongoose.
Here is my Package.json:
{
"name": "drg-coming-soon",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack",
"server": "node server/index.js",
"start": "webpack && node server/index.js",
"react": "webpack -d --watch"
},
"heroku-run-build-script": true,
"author": "Randy Thomas",
"license": "ISC",
"devDependencies": {
"axios": "^0.18.0",
"babel-core": "^6.23.1",
"babel-loader": "^6.3.2",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.23.0",
"body-parser": "^1.18.3",
"express": "^4.15.0",
"jquery": "^3.1.1",
"mongoose": "^6.2.7",
"react-awesome-modal": "^2.0.5",
"request": "^2.81.0",
"webpack": "^4.28.3"
},
"dependencies": {
"axios": "^0.18.0",
"css-loader": "^2.0.1",
"dotenv": "^6.2.0",
"file-loader": "^2.0.0",
"react": "^15.4.2",
"react-autosuggest": "^9.4.3",
"react-dom": "^15.4.2",
"react-image": "^1.5.1",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-scripts": "^2.1.1",
"style-loader": "^0.23.1",
"twilio": "^3.33.2",
"url-loader": "^1.1.2",
"mongoose": "^6.2.7",
"webpack": "^4.28.3"
}
}
Here is my webpack.config.js
const path = require('path');
const SRC_DIR = path.join(__dirname, '/client/src');
const DIST_DIR = path.join(__dirname, '/client/dist');
module.exports = {
entry: `${SRC_DIR}/index.js`,
output: {
filename: 'bundle.js',
path: DIST_DIR,
},
module: {
//changed from loaders to rules
loaders: [
{
test: /\.jsx?/,
include: SRC_DIR,
loader: 'babel-loader',
query: {
presets: [
'#babel/preset-env',
'#babel/preset-react'
],
},
},
],
},
};
Here is my Database folder:
require('dotenv').config();
const mongoose = require('mongoose');
// dev
// process.env.mongourl
mongoose.connect(process.env.mongourl)
.catch(err => console.log('Mongo connection error', err));
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', () => {
console.log('MongoDB has connected');
});
// schemas
const comingSoonSchema = ({
address: String,
desc: String,
sqft: Number,
bed: String,
bath: String,
photoLink: String,
agent: String,
price: String,
year: Number,
eta: String,
premarket: String,
status: String,
timeStamp: { type: Date, default: Date.now },
})
// models
const ComingSoon = mongoose.model('ComingSoon', comingSoonSchema);
function save(e) {
console.log(e, "SAVE FUNC");
const obj = new ComingSoon({
address: e.address,
desc: e.desc,
sqft: e.sqft,
bed: e.bed,
bath: e.bath,
photoLink: e.photoLink,
agent: e.agent,
price: e.price,
year: e.year,
eta: e.eta,
status: e.status,
premarket: e.premarket
})
obj.save();
console.log("Data saved to MongoDB Database");
}
const funcs = {
save, ComingSoon,
};
module.exports = funcs;
And lastly here is the persisting error:
2022-03-23T01:33:06.685994+00:00 heroku[web.1]: Starting process with command `npm start`
2022-03-23T01:33:07.919434+00:00 app[web.1]:
2022-03-23T01:33:07.919447+00:00 app[web.1]: > drg-coming-soon#1.0.0 start
2022-03-23T01:33:07.919448+00:00 app[web.1]: > webpack && node server/index.js
2022-03-23T01:33:07.919448+00:00 app[web.1]:
2022-03-23T01:33:07.965317+00:00 app[web.1]: One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
2022-03-23T01:33:07.965319+00:00 app[web.1]: - webpack-cli (https://github.com/webpack/webpack-cli)
2022-03-23T01:33:07.965319+00:00 app[web.1]: The original webpack full-featured CLI.
2022-03-23T01:33:07.965784+00:00 app[web.1]: We will use "npm" to install the CLI via "npm install -D".
2022-03-23T01:33:08.131129+00:00 app[web.1]: Do you want to install 'webpack-cli' (yes/no): node:internal/modules/cjs/loader:936
2022-03-23T01:33:08.131131+00:00 app[web.1]: throw err;
2022-03-23T01:33:08.131131+00:00 app[web.1]: ^
2022-03-23T01:33:08.131132+00:00 app[web.1]:
2022-03-23T01:33:08.131132+00:00 app[web.1]: Error: Cannot find module 'mongoose'
2022-03-23T01:33:08.131132+00:00 app[web.1]: Require stack:
2022-03-23T01:33:08.131133+00:00 app[web.1]: - /app/database/index.js
2022-03-23T01:33:08.131136+00:00 app[web.1]: - /app/server/index.js
2022-03-23T01:33:08.131136+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-03-23T01:33:08.131137+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2022-03-23T01:33:08.131137+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-03-23T01:33:08.131138+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-03-23T01:33:08.131138+00:00 app[web.1]: at Object.<anonymous> (/app/database/index.js:2:18)
2022-03-23T01:33:08.131139+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1103:14)
2022-03-23T01:33:08.131139+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
2022-03-23T01:33:08.131140+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-03-23T01:33:08.131140+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-03-23T01:33:08.131140+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19) {
2022-03-23T01:33:08.131141+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-03-23T01:33:08.131141+00:00 app[web.1]: requireStack: [ '/app/database/index.js', '/app/server/index.js' ]
2022-03-23T01:33:08.131142+00:00 app[web.1]: }
2022-03-23T01:33:08.265674+00:00 heroku[web.1]: Process exited with status 1
2022-03-23T01:33:08.447674+00:00 heroku[web.1]: State changed from starting to crashed
2022-03-23T01:32:58.202124+00:00 app[api]: Release v158 created by user bookingrlthomas#gmail.com
2022-03-23T01:32:58.202124+00:00 app[api]: Deploy ad551b5e by user bookingrlthomas#gmail.com
2022-03-23T01:33:00.927332+00:00 app[api]: Deploy ad551b5e by user bookingrlthomas#gmail.com
2022-03-23T01:33:00.927332+00:00 app[api]: Release v159 created by user bookingrlthomas#gmail.com
2022-03-23T01:33:51.331557+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=drgcomingsoonlistings.herokuapp.com request_id=fd27788b-e166-49fd-8830-b0da493e7e62 fwd="47.45.81.207" dyno= connect= service= status=503 bytes= protocol=https
2022-03-23T01:33:52.166634+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=drgcomingsoonlistings.herokuapp.com request_id=4967681e-a5a9-41b9-9129-65258f9b9983 fwd="47.45.81.207" dyno= connect= service= status=503 bytes= protocol=https
The error is most likely coming from the fact that you have mongoose in your "devDependencies". Try moving it to your "dependencies", then running npm install. You may run into the same issue with express and a few others under "devDependencies". Hope this helps.
It does not make any sense, but if mongoose is both in dev dependencies and in dependencies, heroku goes nuts. It can be ONLY in dependencies. After deleting it from dev dependencies, do npm install. It will work without any issues.

GraphQL - problem with the code from the tutorial page, it pops up an error "Expected undefined to be a GraphQL schema."

I try to learn GraphQL. I wanted to try out the code that is in the Getting Started With GraphQL.js section in the graphql.org. I created a server.js file like this page says: https://graphql.org/graphql-js/
I followed instructions like:
npm init
npm install graphql --save
The package.json file looks like this:
{
"name": "graphql",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"graphql": "^16.0.1"
}
}
The server.js file I created looks exactly like the one from the page (it was copied):
var { graphql, buildSchema } = require('graphql');
// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
type Query {
hello: String
}
`);
// The root provides a resolver function for each API endpoint
var root = {
hello: () => {
return 'Hello world!';
},
};
// Run the GraphQL query '{ hello }' and print out the response
graphql(schema, '{ hello }', root).then((response) => {
console.log(response);
});
But after using the node server.js command (as written on the page) in the terminal, I get this error:
node_modules\graphql\type\schema.js:35
throw new Error(
^
Error: Expected undefined to be a GraphQL schema.
at assertSchema (F:\GraphQL\node_modules\graphql\type\schema.js:35:11)
at validateSchema (F:\GraphQL\node_modules\graphql\type\validate.js:34:28)
at graphqlImpl (F:\GraphQL\node_modules\graphql\graphql.js:52:64)
at F:\GraphQL\node_modules\graphql\graphql.js:21:43
at new Promise (<anonymous>)
at graphql (F:\GraphQL\node_modules\graphql\graphql.js:21:10)
at Object.<anonymous> (F:\GraphQL\server.js:18:1)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
Does anyone know what the problem is? Maybe I am missing some package? Or the code given on the page is wrong? Please help me, thank you in advance for any answer.

Can't find the module after extension is installed

I'm trying to create VS Code extension. It works when fine when I develop, however when I create the package and install it to VS Code it is failing with following error:
ERR Cannot find module 'request': Error: Cannot find module 'request'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:602:15)
at Function.Module._load (internal/modules/cjs/loader.js:528:25)
at Function.t._load (c:\Users\USER\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:729:537)
at Function.t.getExtensionPathIndex.then.a._load (c:\Users\USER\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:691:639)
at Function.t.getExtensionPathIndex.then.r._load (c:\Users\USER\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:655:197)
at Module.require (internal/modules/cjs/loader.js:658:17)
at n (c:\Users\USER\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\loader.js:15:874)
at openBambooPlanUrlInBrowser.GIT.getGitBranchFromFileName (C:\Users\USER\.vscode\extensions\dUSER.markdown-table-of-contents-0.0.1\out\extension.js:397:41)
at getGitBranchFromFileName.exec (C:\Users\USER\.vscode\extensions\dUSER.markdown-table-of-contents-0.0.1\out\extension.js:383:17)
at ChildProcess.exithandler (child_process.js:294:7)
at ChildProcess.emit (events.js:182:13)
at maybeClose (internal/child_process.js:961:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
my code:
async openBambooPlanUrlInBrowser(fileName: string) {
new GIT().getGitBranchFromFileName(fileName, (branch: string) => {
var config: any = vscode.workspace.getConfiguration('markdown-table-of-contents').get('bitbucketRepositories');
for (var setting of config) {
if (fileName.toLowerCase().startsWith(setting.folder.toLowerCase())) {
branch = branch.replace('/', '-');
let bambooHost = vscode.workspace.getConfiguration('markdown-table-of-contents').get('atlassianBambooHost');
const request = require('request');
request(
{
url: `${bambooHost}/rest/api/latest/plan/${setting.bambooPlanKey}/branch/${branch}.json`,
headers: {
"Authorization": 'Basic ' + vscode.workspace.getConfiguration('markdown-table-of-contents').get('atlassianAuthHash')
}
},
(error: string, response: string, body: string) => {
let planKey = JSON.parse(body).key;
vscode.env.openExternal(vscode.Uri.parse(`${bambooHost}/browse/${planKey}`));
}
);
}
}
});
}
dependencies from package.json
"dependencies": {
"child_process": "^1.0.2",
"clipboardy": "^1.2.3",
"fs": "0.0.1-security",
"iconv-lite": "^0.4.24",
"path": "^0.12.7",
"request": "^2.88.0",
"util": "^0.11.1",
"xml2js": "^0.4.19",
"xmldom": "^0.1.27"
}
root folder:
.gitignore
.vscode
.vscodeignore
depl.bat
markdown-table-of-contents-0.0.1.vsix
node_modules
out
package-lock.json
package.json
src
tsconfig.json
tslint.json
For me the solution was to run npm install <package_name> (notice no "-g") from the extension's code root folder. Vscode puts the extension in its [extension folder][1], navigate there to do npm install.
Example: for linux/mac
cd ~/.vscode/extensions
cd your.extension
npm install
This automatically added it to the devDependencies as well, and the extension worked perfectly from there on.

Use 'request-promise-native' package in DialogFlow inline editor

I am making a POST request to a webservice. The code for POST request is kept in a separate function.The function call from my intent function to the external function is asynchronous.So i am using Promises to achieve synchronicity.The problem here is that when i am importing request-promise-native inside my inline editor it's throwing error as TypeError: Cannot read property 'prototype' of undefined.
But when i tried it in my local workstation which has node js version 9.11.1 it worked fine.The Node JS version in DialogFlow is >=6.0.Is there any other dependency has to be added to it?
Can anyone please explain why this happens?
UPDATE:
I changed the node engine to 6.14.3 and the dependency for the module'request-promise-native' in package.json as "request-promise-native":"v1.0.5".But still no luck.The below is my code:
var doco;
var rp = require('request-promise-native');
var myJSONObject = {
"inputs" : [ {
"name" : "<name>",
"value" : <value>
} ]
};
var orchName = 'TEST05';
postData = JSON.stringify(myJSONObject);
return networkCall(postData,orchName).then((response)=>{
console.log('response is'+response)
console.log("+++++++++++++=DOCO=+++++++++ "+response);
doco = doco1;
//agent.add(`Order number is ${doco1}`);
}).catch((response) => {
console.log(`ERROR: `+response);
});
console.log('doco'+doco);
function networkCall(postData, orchName) {
return new Promise((resolve,reject) =>{
var options = {
method: 'post',
uri: '<URL>',
body: myJSONObject,
auth: {
'user': 'usr',
'pass': 'pwd'
},
json: true
};
return rp( options )
.then( body => {
// var test = JSON.stringify(body)
var doco =body.ServiceRequest1.subforms.z_DOCO_137.value;
console.log('DOCO '+doco);
resolve( doco );
})
.catch( err => {
console.log('FAILED'+err);
reject( err );
});
});
}
The error is thrown once i deploy the code in inline editor.The error is:
The deployment of your Cloud Function failed:
Function load error: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: TypeError: Cannot read property 'prototype' of undefined
at module.exports (/user_code/node_modules/request-promise-native/node_modules/request-promise-core/configure/request2.js:34:47)
at Object.<anonymous> (/user_code/node_modules/request-promise-native/lib/rp.js:15:1)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/index.js:17:23)
The request-promise-native package requires the request package as a co-dependency. So you need to explicitly add this to the package.json tab in the Dialogflow editor.
Here is the package.json that works for me:
{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "~6.0"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "2.0.0-alpha.4",
"firebase-admin": "^4.2.1",
"firebase-functions": "^0.5.7",
"dialogflow": "^0.1.0",
"dialogflow-fulfillment": "0.3.0-beta.3",
"request-promise-native": "^1.0",
"request": "^2.87"
}
}
Don't forget that, in addition to having the correct package, you will need to upgrade the project to a paid account. The free Firebase "Spark" plan does not allow network access outside of Google's network. You can upgrade to the "Blaze" plan which is pay-as-you-go, but does have a free tier which is sufficient for most development and testing purposes.

Openshift 503 on node.js app with hapi

I have a node.js app using hapi that I'm trying to host on OpenShift. I've uploaded the app to the server, it apparently reads the package.json file fine and runs the app.js file.
However, when I visit the site, I receive a 503 error.
Package.json file:
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "server.js",
"dependencies": {
"after": "^0.8.1",
"bcryptjs": "2.3.0",
"bootstrap": "^3.3.6",
"forever": "^0.15.1",
"gulp": "^3.9.0",
"gulp-nodemon": "^2.0.4",
"handlebars": "4.0.5",
"hapi": "^8.8.1",
"hapi-auth-cookie": "^3.1.0",
"knex": "^0.9.0",
"mysql": "^2.9.0",
"nodemon": "^1.8.0",
"request": "^2.69.0",
"tree-model": "^1.0.4"
},
"devDependencies": {},
"scripts": {
"start": "node server.js"
}
"author": "",
"license": "ISC"
}
*note: repository information was removed from the package.json paste.
app.js file:
var Hapi = require('hapi');
var fs = require('fs');
fs.readFile('./bin/dbcfg.txt', 'utf8', function(err, data){
if (err){
console.log(err);
}
else{
data = JSON.parse(data);
process.env.client = data.client;
process.env.host = data.connection.host;
process.env.user = data.connection.user;
process.env.password = data.connection.password;
process.env.database = data.connection.database;
fs.readFile('./bin/strategycfg.txt', 'utf8', function(err, data){
if(err){
console.log(err);
}
else{
var strategyCFG = JSON.parse(data);
server = new Hapi.Server();
server.connection({ port : 3000, address: process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1' });
server.register(require('hapi-auth-cookie'), function(err){
if(err){
console.log(err);
}
server.auth.strategy('default', 'cookie',strategyCFG);
server.auth.default('default');
const defaultContext = {
title: 'App'
};
server.views({
engines: {
html: require('handlebars')
},
context: defaultContext,
path: ['public/html', 'private/html'],
layoutPath: 'public/templates',
layout: 'default'
//,
//helpersPath: 'views/helpers',
//partialsPath: 'views/partials'
});
});
server.route(require('./lib/Routes'));
server.start(function() {
console.log('Running on 3000');
});
}
});
}
});
I ran rhc tail -a appname and received this:
==> app-root/logs/haproxy.log <==
[WARNING] 090/180806 (276379) : config : log format ignored for proxy 'stats' since it has no log address.
[WARNING] 090/180806 (276379) : config : log format ignored for proxy 'express' since it has no log address.
[WARNING] 090/180806 (276379) : Server express/local-gear is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT] 090/180806 (276379) : proxy 'express' has no server available!
[WARNING] 090/180919 (276379) : Server express/local-gear is DOWN for maintenance.
[WARNING] 090/180919 (279772) : config : log format ignored for proxy 'stats' since it has no log address.
[WARNING] 090/180919 (279772) : config : log format ignored for proxy 'express' since it has no log address.
[WARNING] 090/180919 (279772) : Server express/local-gear is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT] 090/180919 (279772) : proxy 'express' has no server available!
[WARNING] 090/180923 (279772) : Server express/local-gear is DOWN for maintenance.
==> app-root/logs/haproxy_ctld.log <==
I, [2016-03-30T22:04:51.536078 #521102] INFO -- : Starting haproxy_ctld
I, [2016-03-30T22:11:34.136340 #49489] INFO -- : Starting haproxy_ctld
I, [2016-03-30T22:25:04.802167 #98826] INFO -- : Starting haproxy_ctld
I, [2016-03-30T22:29:56.842182 #117627] INFO -- : Starting haproxy_ctld
I, [2016-03-30T22:32:36.247075 #130978] INFO -- : Starting haproxy_ctld
I, [2016-03-30T22:39:12.046805 #156995] INFO -- : Starting haproxy_ctld
I, [2016-03-30T23:01:39.741187 #237078] INFO -- : Starting haproxy_ctld
I, [2016-03-30T23:07:00.948129 #255019] INFO -- : Starting haproxy_ctld
I, [2016-03-31T18:08:07.635718 #276393] INFO -- : Starting haproxy_ctld
I, [2016-03-31T18:09:20.552771 #279795] INFO -- : Starting haproxy_ctld
==> app-root/logs/npm-debug.log <==
5 error package.json npm can't find a package.json file in your current directory.
6 error System Linux 2.6.32-573.12.1.el6.x86_64
7 error command "node" "/opt/rh/nodejs010/root/usr/bin/npm" "install"
8 error cwd /var/lib/openshift/xxxxxxxx/app-root/logs
9 error node -v v0.10.35
10 error npm -v 1.4.28
11 error path /var/lib/openshift/xxxxxxxx/app-root/logs/package.json
12 error code ENOPACKAGEJSON
13 error errno 34
14 verbose exit [ 34, true ]
==> app-root/logs/nodejs.log <==
DEBUG: Sending SIGTERM to child...
DEBUG: Running node-supervisor with
DEBUG: program 'server.js'
DEBUG: --watch '/var/lib/openshift/xxxxxxx/app-root/data/.nodewatch'
DEBUG: --ignore 'undefined'
DEBUG: --extensions 'node|js|coffee'
DEBUG: --exec 'node'
DEBUG: Starting child process with 'node server.js'
DEBUG: Watching directory '/var/lib/openshift/xxxxxxx/app-root/data/.nodewatch' for changes.
Running on 3000
The "Running on 3000" makes me think the app is running, but the OpenShift site gives me a 503.
Any and all help would be greatly appreciated. Thanks, everyone!
Can you try to use host instead of address like this:
server.connection({ host:'0.0.0.0', port: 3000});
Also I think open shift also expose an environment variable for the port.

Categories