Setting up Strapi using MongoDB via the PM2 Runtime - mongodb

I'm quite new to Strapi and I'm following the Strapi deployment documentation at https://strapi.io/documentation/3.0.0-beta.x/guides/deployment.html#configuration. I have setup strapi using mongodb and it seems to work both in production and dev on my server. I can create content types and add data...
Now I'm trying to start Strapi using the PM2 Runtime. I have setup the ecosystem.config.js file (see below) and I run pm2 start ecosystem.config.js. The Strapi app seems to start just fine, but now what happens in the browser is that I am prompted with a new admin user. Seems like all users and data is lost... Mongo db not accessed or whats going on?
this is my ecosystem.config.js file
module.exports = {
apps : [{
name: 'cms.strapi',
cwd: '/var/www/domain/public_html',
script: 'server.js',
env: {
NODE_ENV: 'production',
DATABASE_HOST: '127.0.0.1',
DATABASE_PORT: '28015',
DATABASE_NAME: 'db-name',
DATABASE_USERNAME: 'db-u-name',
DATABASE_PASSWORD: 'pw',
},
}],
};
What am I missing?

Hi Jim and thanks for your reply! I believe the problem was a mixup between the prod and the dev environment. Sorry, my bad. I thought I was in one environment when I was really in the other. I guess it should be obvious when you start the server from the prompt whether your starting dev or prod, but once the web server is up and running in the browser I guess you can't tell from the gui whether it's the one or the other. At least I can't find one other than that the admin usernames (and possibly data) are different... Hmm..
Anyway my production/database.json file looks like this:
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "mongoose",
"settings": {
"uri": "mongodb://localhost:27017/db-prod",
"database": "db-prod",
"host": "127.0.0.1",
"srv": false,
"port": 27017,
"username": "u-name-prd",
"password": "pw"
},
"options": {
"ssl": false
}
}
}
}
PM2 Runtime seems to be working correctly with Strapi and Mongo now :-)

Related

Trying to deploy strapi project to Heroku

I have a project which has been based on the top of this tutorial.
I have been trying to deploy to Heroku following both:
1) Strapi docs to deploy to Heroku
2) Install on Atlas: MongoDB Atlas
my prod database config is as follow:
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "mongoose",
"settings": {
"uri": "${process.env.DATABASE_URI}",
"database": "${process.env.DATABASE_NAME}"
},
"options": {
"authenticationDatabase": "admin",
"ssl": true
}
}
}
}
environment variables have been set in Heroku, when I try the prod environment locally it fails with the above config, if I replace the URI string I got from:
I manage to run prod database locally.
Even when I push heroku master and the build is successful I get: https://alex-web-portfolio.herokuapp.com/
and the logs are:

Sails.js - Authorisation issues with remote MongoDB on mLab but working fine locally

Recently, I took over a Sails.js application created for our company by a small team of web developers. They provided me with the source and a database dump. Now, my task is to get it up and running on Heroku. While everything is working okay when I run the app locally, with the remote connection there is an error on startup that says:
MongoError: not authorized on heroku_gbntc8sf to execute command { createIndexes: "agendaJobs", indexes: [ { key: { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, name: "findAndLockNextJobIndex1" }, { key: { name: 1, lockedAt: 1, priority: -1, nextRunAt: 1, disabled: 1 }, name: "findAndLockNextJobIndex2" } ] }
at Function.MongoError.create ([ROOT_DIR]/node_modules/mongodb-core/lib/error.js:31:11)
at [ROOT_DIR]/node_modules/mongodb-core/lib/topologies/server.js:793:66
at Callbacks.emit ([ROOT_DIR]/node_modules/mongodb-core/lib/topologies/server.js:94:3)
at null.messageHandler ([ROOT_DIR]/node_modules/mongodb-core/lib/topologies/server.js:235:23)
at Socket.<anonymous> ([ROOT_DIR]/node_modules/mongodb-core/lib/connection/connection.js:259:22)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at TCP.onread (net.js:523:20)
Here's a quick checklist of what I've done already:
checked the build log on Heroku - no errors or warnings;
set up mLab Heroku add-on, exported the database, done some manual checks from the mLab dashboard - everything looks okay;
logged in to the database remotely from the mongo command and a mongo:// URL, ran a few simple queries, and obtained information on the database user privileges;
created an identical user (with the heroku_gbntc8sf username, same password, same role, etc.) in the local database.
Here's what the connection configuration looks like:
// config/connections.js
module.exports.connections = {
mongodb: {
adapter: 'sails-mongo',
user: 'heroku_gbntc8sf',
password: [HIDDEN],
host: 'ds159387.mlab.com',
port: 59387,
database: 'heroku_gbntc8sf'
},
// ...
}
// config/env/development.js
module.exports = {
models: {
connection: 'mongodb'
},
// ...
}
// config/env/production.js
module.exports = {
models: {
connection: 'mongodb'
},
// ...
}
At the moment I'm running the server locally, trying to connect to the remote database, to eliminate as many variables as possible. Like I mentioned above, when I set host to '127.0.0.1' and port to 27017, everything works okay. The heroku_gbntc8sf user has basic readWrite permissions in both databases (local and remote). In fact, those two databases are pretty much identical, as far as I know. And yet...
I've read a sizeable chunk of the Sails.js documentation, as well as, the documentation on the sails-mongo adapter. I've searched for similar questions, but I couldn't find anything relevant. I've tried many different things, including a couple of different ways to configure the database connection, but that error is always there.
The reason why I'm posting to StackOverflow is that I cannot rely on the support from the original authors of the app at the moment. Also, I'm new to Sails.js, so I might be doing something wrong without even knowing. I was hoping that I could get away with treating the app as a 'black box' (or like a generic Node application), since my job is only to start the app on Heroku.
I've successfully used mLab in a Sails project recently, but I've used the Mongo URL string format, for example...
mongodbServer: {
adapter: 'sails-mongo',
url : "mongodb://dandanknight:som3P455w0rd#ds044979.mlab.com:44979/databasename"
}
Not sure if it helps, but can't hurt to try! It's also the only way I've successfully got a replicaSet working in Sails incidentally.
It's confusing, but I read the sails-mongo docs as "URL is the way forward, and passing an object is legacy usage" (here)

Vapor Framework : Configure a postgres connection with SSL

I'm trying to connect to my Heroku PostgreSQL database but I have the following error :
cannotEstablishConnection("FATAL: no pg_hba.conf entry for host \"37.167.93.189\", user \"clpnkpyttmdtyq\", database \"d3h6147v73mgtu\", SSL off\n")
I know that Heroku postgres databases need to use an SSL connection but I don't know how to configure the connection on my Droplet object.
This is my postgresql.json configuration file :
{
"host": "ec2-54-163-224-108.compute-1.amazonaws.com",
"user": "clpnkpyttmdtyq",
"password": "99201aa07c48e18e7bdf210937857b85bee37cd8d8cb904381b1ddff934c7a4f",
"database": "d3h6147v73mgtu",
"port": 5432
}
Maybe there is ssl parameter that I don't know ?
How I add the VaporPostgresSQLProvider :
let drop = Droplet()
// Tell the droplet to use our SQL provider service
try drop.addProvider(VaporPostgreSQL.Provider.self)
Any ideas ?
When I try with my local postgres database, it works, because it don't need ssl connection.
For Heroku we need unverifiedTLS transport.
https://api.vapor.codes/postgresql/latest/PostgreSQL/Classes/PostgreSQLConnection/TransportConfig.html
let pgURL = Environment.get("DATABASE_URL") ?? "postgres://user:password#host:port/database"
let pgConfig = PostgreSQLDatabaseConfig(url: pgURL, transport: PostgreSQLConnection.TransportConfig.unverifiedTLS)!
it's a process that personally cost me a lot, this solution works for me, try this
On file Config > secrets > postgresql.json add this configuration (for use on local or remote, if this file not exist, create this)
{
"host": "127.0.0.1",
"user": "your_user_pc",
"password": "",
"database": "your_user_pc",
"port": 5432
}
The user can get it from Terminal
$ cd ~
On your file Procfile (sited on your project, show via finder) edit and add this code
web: App --env=production --workdir="./"
web: App --env=production --workdir=./ --config:servers.default.port=$PORT --config:postgresql.url=$DATABASE_URL
Now you can re-launch your application to heroku, you should consider having the server configured correctly from heroku with all its credentials and add-ons of Postgresql from the interface of Heroku
Note: And do not forget every change you make, run "vapor build" or "vapor build --clean"
Vapor 4 + build stack heroku-20 + Heroku Postgres's standard plan
Rijel David's suggestion did the trick for me
But unverifiedTLS syntax has slightly changed
if let databaseURL = Environment.get("DATABASE_URL"), var postgresConfig = PostgresConfiguration(url: databaseURL) {
postgresConfig.tlsConfiguration = .forClient(certificateVerification: .none)
app.databases.use(.postgres(
configuration: postgresConfig
), as: .psql)
} else {
// ...
}
Check out Vapor doc - https://docs.vapor.codes/4.0/deploy/heroku/

Bluemix - error connecting loopback starter with mongoDB compose

I am trying to setup the loopback starter app on Bluemix with MongoDB. I have set up the MongoDB instance in Compose. However, when I keep getting a connection error even though I have followed all instructions and can even connect using the mongo shell.
{ [MongoError: connect ECONNREFUSED] name: 'MongoError', message: 'connect ECONNREFUSED' }
Take a look here: http://www.technicaladvices.com/2015/10/06/deploying-your-existing-strongloop-application-to-ibm-bluemix/
It shows the details of deploying a "StrongLoop" app in IBM Bluemix.
If the issue is still there open a support request directly from your Bluemix console or you can open a new ticket here: https://support.ng.bluemix.net/gethelp/
I was able to solve the problem by using the following configuration format in datasources.json:
"mongoDs": {
"host": "candidate.53.mongolayer.com",
"port": 10852,
"database": "SiteRite",
"username": "xxxx",
"password": "xxxx",
"name": "mongoDs",
"connector": "mongodb"
}
NOT using the 'url' key and using 'host' and 'port' with a separate 'username' and 'password' for the database is what seemed to have fixed it.

Remote MongoDB access through Cloud 9 gives login failed exception

I'm using the Cloud 9 IDE to develop an application using MongoDB. I created a database called "appdata" at MongoLab and the following user:
{
"_id": "appdata.admin",
"user": "admin",
"db": "appdata",
"credentials": {
"SCRAM-SHA-1": {
"iterationCount": 10000,
"salt": "K/WUzUDbi3Ip4Vy59gNV7g==",
"storedKey": "9ow35+PtcOOhfuhY7Dtk7KnfYsM=",
"serverKey": "YfsOlFx1uvmP+VaBundvmVGW+3k="
}
},
"roles": [
{
"role": "dbOwner",
"db": "appdata"
}
]
}
Whenever I try connecting to the database through Cloud 9 Shell using the following command (given by MongoLab with my newly created user):
mongo ds057244.mongolab.com:57244/appdata -u admin -p admin
I get the following error message:
MongoDB shell version: 2.6.11
connecting to: ds057244.mongolab.com:57244/appdata
2015-11-22T05:23:49.015+0000 Error: 18 { ok: 0.0, errmsg: "auth failed",
code: 18 } at src/mongo/shell/db.js:1292
exception: login failed
Also, on my javascript file running on Cloud 9, while following this tutorial (which uses mongoose to access the DB) I got stuck on the post route for bears. Whenever I send a post request through postman with the specified fields set, the route doesn't return anything, neither a bear created nor an error message, which makes me think the problem is also failing to login to the database. The previous get request is working just fine and my code is the exactly same as the tutorial.
Does anyone know what the problem in any of the cases and what I need to do to solve them?
The shell problem was fixed updating it to the Database version (which was 3.0.3).
For the javascript files, I restarted the tutorial and made sure I downloaded all necessary dependencies with the most recent stable version (not the ones shown on the tutorial), after that the problem was solved.