Skip to content

Commit

Permalink
fix(config): rectifie les valeurs de config par défaut
Browse files Browse the repository at this point in the history
  • Loading branch information
thom4parisot committed Nov 18, 2024
1 parent ea3507b commit 67384df
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 29 deletions.
3 changes: 1 addition & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ services:
env_file:
- .env
environment:
- MONGO_SERVER=mongodb-stylo
- MONGO_SERVER_PORT=27017
- DATABASE_URL=mongodb://mongodb-stylo:27017/stylo-dev
ports:
- 127.0.0.1:3030:3030

Expand Down
6 changes: 1 addition & 5 deletions graphql/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ const wss = new WebSocket.Server({ noServer: true })

const app = express()

const mongoServer = config.get('mongo.host')
const mongoServerPort = config.get('mongo.port')
const mongoServerDB = config.get('mongo.db')

const listenPort = config.get('port')
const origin = config.get('security.cors.origin')
const jwtSecret = config.get('security.jwt.secret')
Expand Down Expand Up @@ -320,7 +316,7 @@ mongoose.set('useCreateIndex', true)
mongoose.set('useFindAndModify', false)

mongoose
.connect(`mongodb://${mongoServer}:${mongoServerPort}/${mongoServerDB}`)
.connect(config.get('mongo.databaseUrl'))
.then(() => {
logger.info('Listening on http://localhost:%s', listenPort)
const server = app.listen(listenPort)
Expand Down
36 changes: 17 additions & 19 deletions graphql/config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
const convict = require('convict')
const assert = require('node:assert/strict')
require('dotenv').config({ path: ['.env', '../.env'] })

const isURL = require('validator/lib/isURL')

convict.addFormat(require('convict-format-with-validator').url)
convict.addFormat({
name: 'mongodb-url',
coerce: (v) => v.toString(),
validate: (val) => assert.ok(isURL(val, { require_tld: false, protocols: ['mongodb', 'mongodb+srv'] }), 'must be a mongodb protocol URL')

})
/**
* @type {convict.Config<{
*
Expand All @@ -22,32 +30,22 @@ module.exports = convict({
}
},
mongo: {
db: {
format: String,
env: 'MONGO_SERVER_DB',
default: 'stylo-dev'
},
host: {
format: String,
env: 'MONGO_SERVER',
default: '127.0.0.1'
},
port: {
format: 'port',
env: 'MONGO_SERVER_PORT',
default: '27017'
databaseUrl: {
default: 'mongodb://127.0.0.1:27017/stylo-dev',
format: 'mongodb-url',
env: 'DATABASE_URL'
}
},
oauthProvider: {
name: {
format: String,
env: 'OPENID_CONNECT_NAME',
default: null,
default: null
},
issuer: {
format: 'url',
env: 'OPENID_CONNECT_ISSUER',
default: null,
default: null
},
callbackUrl: {
format: 'url',
Expand Down Expand Up @@ -76,12 +74,12 @@ module.exports = convict({
tokenUrl: {
format: 'url',
env: 'OPENID_CONNECT_TOKEN_URL',
default: null,
default: null
},
userInfo: {
format: 'url',
env: 'OPENID_CONNECT_USER_INFO_URL',
default: null,
default: null
},
url: {
format: 'url',
Expand Down Expand Up @@ -113,7 +111,7 @@ module.exports = convict({
format: String,
sensitive: true,
env: 'JWT_SECRET_SESSION_COOKIE',
default: null,
default: null
}
},
session: {
Expand Down
2 changes: 1 addition & 1 deletion graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "graphql-stylo",
"version": "3.1.5",
"description": "",
"main": "index.js",
"main": "app.js",
"private": true,
"engines": {
"node": ">=18",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"version": "3.1.5",
"description": "Stylo est un éditeur de textes pour articles scientifiques en sciences humaines et sociales.",
"main": "index.js",
"main": "graphql/app.js",
"directories": {
"doc": "docs"
},
Expand All @@ -14,7 +14,7 @@
"scripts": {
"dev": "DOTENV_CONFIG_PATH=.env node -r dotenv/config ./node_modules/.bin/concurrently 'npm:dev:*'",
"dev:front": "./front/node_modules/.bin/vite ./front",
"predev:graphql": "DOTENV_CONFIG_PATH=stylo.env node -r dotenv/config ./graphql/node_modules/.bin/db-migrate up --migrations-dir ./graphql",
"predev:graphql": "DOTENV_CONFIG_PATH=stylo.env node -r dotenv/config ./graphql/node_modules/.bin/db-migrate up --migrations-dir ./graphql/migrations",
"dev:graphql": "node --watch ./graphql/app.js --watch",
"dev:export": "node --watch ./export/src/app.js --watch",
"start": "DOTENV_CONFIG_PATH=.env node -r dotenv/config ./node_modules/.bin/concurrently 'npm:start:*'",
Expand Down

0 comments on commit 67384df

Please sign in to comment.