I can't connect to my db,
i use mongodb atlas and heroku
first, my error code
2022-10-10T00:59:14.722647+00:00 heroku[web.1]: State changed from crashed to starting
2022-10-10T00:59:17.167527+00:00 heroku[web.1]: Starting process with command node app.js
2022-10-10T00:59:20.911026+00:00 heroku[web.1]: State changed from starting to up
2022-10-10T00:59:48.837201+00:00 app[web.1]: /app/node_modules/mongodb/lib/utils.js:365
2022-10-10T00:59:48.837215+00:00 app[web.1]: throw error;
2022-10-10T00:59:48.837216+00:00 app[web.1]: ^
2022-10-10T00:59:48.837216+00:00 app[web.1]:
2022-10-10T00:59:48.837217+00:00 app[web.1]: Error: Error connecting to db: connect ECONNREFUSED 127.0.0.1:27017
2022-10-10T00:59:48.837218+00:00 app[web.1]: at /app/node_modules/connect-mongodb-session/index.js:88:17
2022-10-10T00:59:48.837218+00:00 app[web.1]: at /app/node_modules/mongodb/lib/utils.js:361:17
2022-10-10T00:59:48.837219+00:00 app[web.1]: at
/app/node_modules/mongodb/lib/mongo_client.js:116:28
2022-10-10T00:59:48.837219+00:00 app[web.1]: at connectCallback
(/app/node_modules/mongodb/lib/operations/connect.js:29:9)
2022-10-10T00:59:48.837220+00:00 app[web.1]: at /app/node_modules/mongodb/lib/operations/connect.js:79:20
2022-10-10T00:59:48.837220+00:00 app[web.1]: at exitWithError (/app/node_modules/mongodb/lib/sdam/topology.js:186:53)
2022-10-10T00:59:48.837220+00:00 app[web.1]: at /app/node_modules/mongodb/lib/sdam/topology.js:190:59
2022-10-10T00:59:48.837221+00:00 app[web.1]: at /app/node_modules/mongodb/lib/sdam/topology.js:242:80
2022-10-10T00:59:48.837221+00:00 app[web.1]: at
2022-10-10T00:59:48.837221+00:00 app[web.1]:
2022-10-10T00:59:48.837222+00:00 app[web.1]: Node.js v18.7.0
2022-10-10T00:59:48.846833+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/" host=fast-retreat-13963.herokuapp.com request_id=76bb3f4b-344d-4207-b8e5-f82f0aa8a24c fwd="59.13.121.53" dyno=web.1 connect=0ms service=24199ms status=503 bytes= protocol=https
i use enviroment value in database
let mongodbUrl = process.env.MONGODB_URI;
if (mongodbUrl == null || mongodbUrl == "") {
mongodbUrl = "mongodb://127.0.0.1:27017";
}
async function connectToDatabse(){
const client = await MongoClient.connect(mongodbUrl)
database = client.db("shopping-project")
}
i igonre my node_modules to gitingore
/node_modules
npm-debug.log
.DS_Store
/*.env
herouku port
let port = process.env.PORT;
if (port == null || port == "") {
port = 3000;
}
db.connectToDatabse().then(function(){
app.listen(port)
}).catch(function(error){
console.log(error)
})
i resist Config Vars in heroku also
key
MONGODB_URI
value
mongodb+srv://audtlr:enterpassword#cluster0.mzdaqy1.mongodb.net/?retryWrites=true&w=majority
plase help me what im going to fix this...
I have been using the official Strapi tutorial on how to deploy strapi to heroku with postgres and after following all the instructions, my heroku app is showing an error. However when I check the build logs, there are no errors and they show the build successful message.
build logs
2020-08-17T15:48:19.744258+00:00 app[web.1]: npm ERR!
2020-08-17T15:48:19.744486+00:00 app[web.1]: npm ERR! Failed at the radio-darya-backend#0.1.0 start script.
2020-08-17T15:48:19.744753+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-08-17T15:48:19.756754+00:00 app[web.1]:
2020-08-17T15:48:19.757071+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-08-17T15:48:19.757252+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-08-17T15_48_19_747Z-debug.log
2020-08-17T15:48:19.825573+00:00 heroku[web.1]: Process exited with status 1
2020-08-17T15:48:19.869487+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-17T15:48:32.221633+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=radio-darya-backend.herokuapp.com request_id=1bceee5d-4452-4b2a-9638-d5f242b4337c fwd="213.162.246.193" dyno= connect= service= status=503 bytes= protocol=https
2020-08-17T15:48:32.751425+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=radio-darya-backend.herokuapp.com request_id=95d4de1a-5f17-49e3-bed2-b459bce9259e fwd="213.162.246.193" dyno= connect= service= status=503 bytes= protocol=https
package.json dependencies
"devDependencies": {},
"dependencies": {
"knex": "<0.20.0",
"pg": "^8.3.0",
"sqlite3": "latest",
"strapi": "3.1.4",
"strapi-admin": "3.1.4",
"strapi-connector-bookshelf": "3.1.4",
"strapi-plugin-content-manager": "3.1.4",
"strapi-plugin-content-type-builder": "3.1.4",
"strapi-plugin-email": "3.1.4",
"strapi-plugin-upload": "3.1.4",
"strapi-plugin-users-permissions": "3.1.4",
"strapi-utils": "3.1.4"
},
config database.js
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
"client":"postgres",
"host":"${process.env.DATABASE_HOST}",
"port": "${process.env.DATABASE_PORT}",
"database": "${process.env.DATABASE_NAME}",
"username": "${process.env.DATABASE_USERNAME}",
"password": "${process.env.DATABASE_PASSWORD}",
"ssl": { "rejectUnauthorized": false }
},
options: {
},
},
},
});
her
This is working for me for v3.x strapi.
// Path: ./config/env/production/database.js
const parse = require('pg-connection-string').parse;
const config = parse(process.env.DATABASE_URL);
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client: 'postgres',
host: config.host,
port: config.port,
database: config.database,
username: config.user,
password: config.password,
},
options: {
ssl: false,
},
},
},
});
We also need to set the NODE_ENV variable on Heroku to production to ensure this new database configuration file is used.
heroku config:set NODE_ENV=production
see https://strapi.io/documentation/v3.x/deployment/heroku.html
Note here is v3.x instead of beta version. Google "strapi heroku postgres" for the moment still give legacy beta version.
You didn’t give the error message you’re having?
I did deploy my strapi to heroku a few weeks ago and there was no problems.
You are sure you followed all the steps from strapi documentation?
Only thing I could think to go wrong is database connection.
First you have to install postgress addon in Heroku, then get the config-info and last add environment variables in Heroku (settings/config vars) and also modify strapi config-files to get the database information from environment variables.
Strapi documentation: https://strapi.io/documentation/3.0.0-beta.x/deployment/heroku.html.
EDIT:
Strapi documentation isn’t correct at the moment, database.json file and location has been changed. See:
strapi database.js / multiple database configs
https://www.youtube.com/watch?v=xNE0TrI5OKk
ive just completed that tutorial a day ago... and i also had problems for a complete beginner to strapi and postgres and heroku... heres my experience.
follow along here to get postgres and the database setup:
https://tute.io/install-configure-strapi-postgresql
then complete your setup with the missing pieces from here:
https://strapi.io/documentation/v3.x/deployment/heroku.html
basically:
have postgres installed locally on your system, create the db and user and grant permissions.
install strapi without the quickstart flag and use the details that was used above.
use the heroku cli to set the configs derived from the database_url configvar.
commit and push and all should be well.
EDIT:
In Heroku under the app in question:
click setting and scroll down to Environment variable and click Reveal Config Vars
Ensure that you have a DATABASE_URL config var
Ensure that your postgres specific config vars match up to the DATABASE_URL
eg. DATABASE_URL = postgres://ebitxebvixeeqd:dc59b16dedb3a1eef84d4999sb4baf#ec2-50-37-231-192.compute-2.amazonaws.com: 5432/d516fp1u21ph7b
It's read like so: postgres:// USERNAME : PASSWORD # HOST : PORT : DATABASE_NAME
Also in your ./config/server.js file make sure your host is 0.0.0.0
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
admin: {
auth: {
secret: env('ADMIN_JWT_SECRET', '***********************'),
},
},
});
Also change your database.js config to be:
settings: {
client: 'postgres',
host: env('DATABASE_HOST', '127.0.0.1'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'strapi'),
username: env('DATABASE_USERNAME', 'postgres'),
password: env('DATABASE_PASSWORD', ''),
ssl: env.bool('DATABASE_SSL', false),
},
options: {}
Theres no much to go on from your question or the logs, but the above is basically some common issues ive experienced.
copy this code directly in the config/database.js
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client:'postgres',
host:`${process.env.DATABASE_HOST}`,
port: `${process.env.DATABASE_PORT}`,
database: `${process.env.DATABASE_NAME}`,
username: `${process.env.DATABASE_USERNAME}`,
password: `${process.env.DATABASE_PASSWORD}`,
ssl: { "rejectUnauthorized": false }
},
options: {
},
},
},
});
After updating my parse-dashboard i lost the "logs column" as you can see:
I just upgraded my parse-dashboard and my parse server:
dashboard: ?.?.? (package.json https://pastebin.com/KRFaxJha)
parse-server: 2.4.0
node: 7.10.0
This is my parse-dashboard configuration file:
{
"apps": [
{
"appId": "APP_ID",
"masterKey": "MASTER_KEY",
"restKey": "REST_KEY",
"serverURL": "http://WWW_WEBSITE:8081/parse",
"appName":"APP_NAME"
}
],
"users": [
{
"user": "ADMIN",
"pass": "ADMINXXXXXXX"
}
]
}
This is my cloud code test function:
Parse.Cloud.define("hello", function(request, response) {
response.success("Hello world!");
});
When i call it with a curl i have:
curl -X POST -H "X-Parse-Application-Id: APP_ID" -H "X-Parse-REST-API-Key: REST_KEY" -H "Content-Type: application/json" -d '{ }' http://WWW_WEBSITE:8081/parse/functions/hello
{"result":"Hello world!"}
the result is correct and on the parse server i have the trace:
verbose: REQUEST for [POST] /parse/functions/hello: {} method=POST, url=/parse/functions/hello, user-agent=curl/7.29.0, host=WWW_WEBSITE:8081, accept=*/*, x-parse-application-id=APPID, x-parse-rest-api-key=REST_KEY, content-type=application/json, content-length=3,
info: Ran cloud function hello for user undefined with:
Input: {}
Result: "Hello world!" functionName=hello, , user=undefined
verbose: RESPONSE from [POST] /parse/functions/hello: {
"response": {
"result": "Hello world!"
}
} result=Hello world!
I have seen this topic:
https://github.com/parse-community/parse-dashboard/issues/281
and i have try to set the verbose export variable on my parse-server and dashboard
i think i have miss some configuration but i can't find which one,
Thanks a lot,
Canna
Bad dashboard version i don't know why:
npm install -g parse-dashboard fix it and installed the good dashboard version
I migrated my app to heroku + mlab from parse. I would too often get request timeout error on the logs. I turned on verbose and below is what i get when a timeout happens:
2016-05-25T15:27:40.946050+00:00 app[web.1]: [36mverbose[39m: POST /parse/events/AppOpened { host: 'dairy-oneandahalf.herokuapp.com',
2016-05-25T15:27:40.946067+00:00 app[web.1]: connection: 'close',
2016-05-25T15:27:40.946074+00:00 app[web.1]: 'x-parse-app-build-version': '1',
2016-05-25T15:27:40.946084+00:00 app[web.1]: "__type": "Date"
2016-05-25T15:27:41.517425+00:00 app[web.1]: [36mverbose[39m: GET /parse/classes/_User { host: 'dairy-oneandahalf.herokuapp.com',
2016-05-25T15:27:41.517436+00:00 app[web.1]: connection: 'close',
2016-05-25T15:27:41.517445+00:00 app[web.1]: 'x-parse-client-version': 'i1.13.0',
2016-05-25T15:27:41.517448+00:00 app[web.1]: 'x-forwarded-for': '58.152.243.212',
2016-05-25T15:27:40.948269+00:00 heroku[router]: at=info method=POST path="/parse/events/AppOpened" host=dairy-oneandahalf.herokuapp.com request_id=3e9b1390-a1b8-487b-8229-f4c44777b2a4 fwd="58.152.243.212" dyno=web.1 connect=2ms service=6ms status=200 bytes=483
2016-05-25T15:28:12.746545+00:00 app[web.1]: [36mverbose[39m: GET /parse/classes/allPosts { host: 'dairy-oneandahalf.herokuapp.com',
2016-05-25T15:28:12.746591+00:00 app[web.1]: connection: 'close',
2016-05-25T15:28:12.746600+00:00 app[web.1]: 'x-request-id': '84c7c271-4725-42c2-a111-3cf8e2c16d52',
2016-05-25T15:28:12.746602+00:00 app[web.1]: 'total-route-time': '0',
2016-05-25T15:28:12.746605+00:00 app[web.1]: "query": {
2016-05-25T15:28:11.513492+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/parse/classes/_User" host=dairy-oneandahalf.herokuapp.com request_id=1260ec0f-3cee-4c43-a87e-9146ef154e29 fwd="58.152.243.212" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0
I'm very new to heroku, can somebody explain to me what is wrong and what I can do about solving it? any help will be greatly appreciated, thanks in advance
I implemented a project configured with OmniAuth/Twitter and OmniAuth/Facebook. in development mode with any problem.
But when i tried on heroku. it refused to work.
use Rack::Session::Cookie
use OmniAuth::Builder do
provider :twitter, ENV['TWITTER_APP_ID'], ENV['TWITTER_SECRET']
provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET'], :scope => 'email'
end
Heroku logs
012-11-02T03:28:47+00:00 app[web.1]: E, [2012-11-02T03:28:47.339453 #58] ERROR -- omniauth: (twitter) Authentication failure! invalid_credentials: OAuth::Unauthorized, 401 Unauthorized
2012-11-02T03:28:47+00:00 heroku[router]: GET p####.herokuapp.com/auth/twitter/callback?oauth_token=r6l3GpwmxH38W8Q9WltcWs9PqyyGxxiGAUqXGFhmKs&oauth_verifier=O9HD6jLaEL1aRUcORIebGEZIQHbqtcgB012q5aZlCE dyno=web.1 queue=0 wait=0ms service=368ms status=302 bytes=9
2012-11-02T03:28:47+00:00 app[web.1]: 92.160.179.137 - - [02/Nov/2012 03:28:47] "GET /auth/failure?message=invalid_credentials&origin=https%3A%2F%2F p####.herokuapp.com%2Flogin&strategy=twitter HTTP/1.1" 200 3160 0.0033
2012-11-02T03:28:47+00:00 heroku[router]: GET p####.herokuapp.com/auth/failure?message=invalid_credentials&origin=https%3A%2F%2F p####.herokuapp.com%2Flogin&strategy=twitter dyno=web.1 queue=0 wait=0ms service=8ms status=200 bytes=3160
Thanks
A few things. Run $ heroku config and make sure the right keys are on Heroku.
Also, not sure about Twitter, but Facebook requires a callback url that you put in the settings for your app on developer.facebook.com, and that needs to point to the heroku url or it will be invalid.
Another long shot, but it could be an issue with CA certificates. I had that problem and fixed it with this in an initializer:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET'], {
client_options: { ssl: {
ca_file: '/usr/lib/ssl/certs/ca-certificates.crt',
ca_path: "/etc/ssl/certs"
}}
}
end
Hope this helps some..