Strapi changing mongo uri has no effect - node.js

I've created a Strapi cms instance connecting to a remote Atlas db.
Now I have to create some more environments so I'm trying to change the development database uri.
but changing the uri in config/environments/development/database.json has. no effect.
I'm:
Changing the value
Running strapi build
Running strapi develop
all the old content is still there

Not everything is stored in the database, model settings are stored in files

You should change the values of the file:
Path: ./config/environments/(development|production)/database.json.
example:
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-mongoose",
"settings": {
"client": "mongo",
"host": "ds125048.mlab.com",
"port": "25048",
"database": "myapp-development",
"username": "myusername",
"password": "mypassword"
},
"options": {
"authenticationDatabase": "myapp-development",
"ssl": false
}
}
}
}
Then re-deploy to your app
more details

Related

how can I load configuration for kubernetes using kubernetes-client. Google Cloud

I have TS application that uses kubernetes-client library to connect to kubernetes in Google Cloud.
import { KubeConfig, CoreV1Api } from "#kubernetes/client-node";
const kc = new KubeConfig();
kc.loadFromDefault();
const kbsCoreApi = kc.makeApiClient(CoreV1Api);
When running locally works great, but when I dockerize it, it does not work due to not knowing how to load configuration. I tried to create a config file and load it using "kc.loadFromFile('~/some/path')" instead but It seems that I am missing something it gives me a HTTP error. Here is my configuration file.
{
"kind": "Config",
"apiVersion": "v1",
"clusters": [
{
"name": "cluster1",
"cluster": {
"certificate-authority-data": "cert-data",
"server": "https://128.1.1.2"
}
}
],
"users": [
{
"name": "cluster1",
"user": {
"password": "myPassword",
"usernmae": "myUsername"
}
}
],
"contexts": [
{
"name": "cluster1",
"context": {
"cluster": "cluster1",
"user": "cluster1"
}
}
],
"current-context": "cluster1"
}
Use kc.loadFromCluster(); instead of the kc.loadFromDefault(); used in your code.
See in-cluster example
When starting the client with the in-cluster authentication, it will use the ServiceAccount token on /var/run/secrets/kubernetes.io/serviceaccount
Also make sure that this ServiceAccount has the RBAC permissions for the resource operations that your client code use. But you should be able to get proper error messages, unless.

unable to use environment variables in strapi

I am trying to connect a MongoDB URI to the strapi backend.
I am able to connect with the main URL but when I created a .env.development variable, I am not able to connect to the database.
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "mongoose",
"settings": {
"uri": "${process.env.DATABASE_URI || ''}"
},
"options": {
"ssl": true
}
}
}
}
Ok, new plan.
try that :
npm install --save dotenv
require('dotenv').config()
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "mongoose",
"settings": {
"uri": `${process.env.DATABASE_URI || ''}`
},
"options": {
"ssl": true
}
}
}
}
I am new to programming and strapi. Just want to share i have problem with deploying to heroku with the same problem. I fix it with this:
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "mongoose",
"settings": {
"uri": "${process.env.DATABASE_URI}",
"database": "${process.env.DATABASE_NAME}"
},
"options": {
"ssl": true
}
}
}
}
If you are deploying to heroku please check the environment variables. When I set environment variables using heroku cli it does not save the whole string. I have to copy and paste to the heroku website directly.

How to deploy strapi on google cloud platform?

I'm trying to deploy strapi on google cloud app engine (standard env) but I keep getting a 500 server error. I googled all over but no guides have been written on how to successfully deploy strapi on AE.
I tried the suggestions on this thread: https://github.com/strapi/strapi/issues/2146
So I have:
the gcp-build script to install dependencies
an entrypoint in app.yaml to start strapi
my database.json and server.json in strapi are updated
But it does not seem to work for me. I keep getting the following error:
I tried googling that error "app/invalid" but I can't seem to find anything about that.
I also gave the flex env a spin but that failed as well (without a proper error).
This is my app.yaml file:
runtime: nodejs10
instance_class: F2
service: admin
entrypoint: node_modules/strapi/bin/strapi.js
env_variables:
DATABASE_HOST: "host"
DATABASE_PORT: 27017
DATABASE_NAME: "db"
DATABASE_USERNAME: "name"
DATABASE_PASSWORD: "pw"
DATABASE_SRV: true
DATABASE_AUTHENTICATION_DATABASE: "admin"
DATABASE_SSL: true
NODE_ENV: "production"
PORT: 1337
This is my package.json (important parts):
...
"scripts": {
"strapi": "node_modules/strapi/bin/strapi.js",
"gcp-build": "node node_modules/strapi/lib/utils/post-install.js && cd admin && npm run setup"
}
...
"engines": {
"node": ">=10.0.0",
"npm": ">=6.0.0"
},
production database.json:
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-hook-mongoose",
"settings": {
"client": "mongo",
"host": "host",
"port": 27017,
"database": "db",
"username": "name",
"password": "pw",
"srv": true
},
"options": {
"authenticationDatabase": "admin",
"ssl": true
}
}
}
}
And finally this is my server.json file:
{
"host": "https://admin-dot-ootje-website.appspot.com",
"port": 1337,
"production": true,
"proxy": {
"enabled": false
},
"autoReload": {
"enabled": false
},
"cron": {
"enabled": false
},
"admin": {
"autoOpen": false
}
}
I would expect that this works from the getting started guides in AE but it would seem I'm missing something. Does someone know what that error means? Did someone manage to already deploy strapi on AE?
If I get it working I'd like to add it to strapi docs or medium post for other people to find it easier than I did :)
Thanks in advance!
I think your problem provide from server.json file.
This configuration works on my side :
{
"host": "localhost",
"port": "${process.env.PORT || 1337}",
"production": true,
"proxy": {
"enabled": false
},
"autoReload": {
"enabled": false
},
"cron": {
"enabled": false
},
"admin": {
"autoOpen": false
}
}
I'm working on a new configuration file in order to have the auth provider working... and some other features. But this first version is working for me.
I keep you update of my search if you need.
## Update 1 ##
I found the good configuration for GCP in production mode.
I share it if anyone else need it :
{
"host": "localhost",
"port": "${process.env.PORT || 1337}",
"production": true,
"proxy": {
"enabled": true,
"ssl": true,
"host": "[project-name].appspot.com",
"port": 443
},
"autoReload": {
"enabled": false
},
"cron": {
"enabled": false
},
"admin": {
"autoOpen": false
}
}
I use flexible environment on GCP, but this will work in standard mode I think.
Thanks,

Connect to mLab mongoDB database using nodeJS Strapi

I just got started using strapi framework and I would like to use mLab as my mongoDB database, so I go to configure strapi and fill the following details:
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-mongoose",
"settings": {
"client": "mongo",
"host": "localhost",
"port": 27017,
"database": "development",
"username": "",
"password": ""
},
"options": {}
}
}
}
The details I get from mLab are:
mongodb://myUsername:myPassword#ds047891.mlab.com:41365/myDatabase
Here is my final config:
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-mongoose",
"settings": {
"client": "mongo",
"host": "ds047891.mlab.com",
"port": 41365,
"database": "myDatabase",
"username": "myUsername",
"password": "myPassword"
},
"options": {}
}
}
}
When I try to start strapi, I get the following error:
DEBUG (2748 on DESKTOP-HAL1ATE): Server wasn't able to start properly.
ERROR (2748 on DESKTOP-HAL1ATE): (hook:mongoose) takes too long to load
I think that I did not setup my configuration right, but I can't pinpoint where the problem is. I hope someone could, thanks.
I am Pierre, on of the creators of Strapi. I tried with the following configuration and it worked well:
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-mongoose",
"settings": {
"client": "mongo",
"host": "ds135777.mlab.com",
"port": "35777",
"database": "myDatabase",
"username": "myUsername",
"password": "myPassword"
},
"options": {}
}
}
}
Our configurations files look quiet similar.
What file did you updated (/config/environment/development/database.json or /config/environment/production/database.json)?
Are you sure you entered the correct username and password? Did you try to login to your MongoDB instance through the command line mongo ds135777.mlab.com:35777/myDatabase -u <dbuser> -p <dbpassword>?
UPDATE
In version >= 3 for mlab don't forget to specify authenticationDatabase
"options": {
"authenticationDatabase": "your_mlad_database_name",
"ssl": false
}

Configure node.js chat

I am trying to install and run this node.js chat: https://github.com/dual3nigma/Mejorando.la-Chat.
When I type "npm install" and "node server" it starts, but with an Express error. I think the reason is in the config.json file.
This is my config.json file. I've only changed the db name and port of the config.sample.json file and added my twitter / facebook keys:
{
"port": 721,
"host": "localhost",
"db": {
"name": "V1chatCCI"
},
"twitter": {
"consumerKey": "XXXXXXXXXXXXXXXXXXXXXXXXXX",
"consumerSecret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
"facebook": {
"appId": "XXXXXXXXXXXXXXXXXXXXXXXX",
"appSecret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
"session": {
"secret": "",
"key": ""
},
"cookie": {
"secret": ""
},
"secure": false,
"loginsecure": false,
"key": "",
"cert": "",
"sentry": "dsn"
}
What do I need to put in the session secret/key section? The error on localhost:721 is:
Express
500 Error: secret option required for sessions
You should be able to put anything in those sections, as they're used used internally by express handling sessions. Any values (even just random strings) should fix your problem.

Resources