Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mise à jour vers MongoDB 5 #1320

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Plus d'informations sur [la documentation](http://stylo-doc.ecrituresnumeriques.
# Pré-requis

- Node.js v22+
- MongoDB 4.4
- MongoDB 5

## Sous MacOS

Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
mongodb-stylo:
image: mongo:4.4
# to keep in sync with ./graphql/jest-mongodb-config.js / README.md
image: mongo:5
container_name: 'mongodb-stylo'
environment:
- MONGO_DATA_DIR=/data/db
Expand Down
58 changes: 35 additions & 23 deletions graphql/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
const cors = require('cors')

const session = require('express-session')
const MongoStore = require('connect-mongo')(session)
const MongoStore = require('connect-mongo')
const passport = require('passport')
const OidcStrategy = require('passport-openidconnect').Strategy
const LocalStrategy = require('passport-local').Strategy
Expand Down Expand Up @@ -99,7 +99,7 @@
const allowedOrigins = (origin ?? '')
.split(' ')
.filter((v) => v)
.map((o) => new RegExp('^' + o))

Check warning on line 102 in graphql/app.js

View workflow job for this annotation

GitHub Actions / build / build

Found non-literal argument to RegExp Constructor
// SameSite should be None on cross-site response.
// Please note that "SameSite=None" must also specify the Secure attribute (they require a secure context/HTTPS).
const sameSiteCookies =
Expand All @@ -115,8 +115,22 @@
},
}

const app = express()
/*
* Setup database
*/
const mongooseP = mongoose
.connect(config.get('mongo.databaseUrl'), {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: true,
})
.then((m) => m.connection.getClient())

/*
* Setup App
*/
const app = express()
config.get('sentry.dsn') && Sentry.setupExpressErrorHandler(app)

passport.use(
Expand Down Expand Up @@ -220,7 +234,11 @@
resave: false,
proxy: true,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection }),
store: MongoStore.create({
clientPromise: mongooseP,
autoRemove: 'native',
touchAfter: 12 * 3600,
}),
cookie: {
httpOnly: true,
secure: secureCookie,
Expand Down Expand Up @@ -365,25 +383,19 @@
// Collaborative Writing Websocket
wss.on('connection', setupWSConnection)

// fix deprecation warnings: https://mongoosejs.com/docs/deprecations.html
mongoose.set('useNewUrlParser', true)
mongoose.set('useUnifiedTopology', true)
mongoose.set('useCreateIndex', true)
mongoose.set('useFindAndModify', false)

mongoose
.connect(config.get('mongo.databaseUrl'))
.then(() => {
logger.info('Listening on http://localhost:%s', listenPort)
const server = app.listen(listenPort)
server.on('upgrade', (request, socket, head) => {
wss.handleUpgrade(request, socket, head, function handleAuth(ws) {
// const jwtToken = new URL('http://localhost' + request.url).searchParams.get("token")
// TODO: check token and permissions
wss.emit('connection', ws, request)
})
})
})
.catch((err) => {
const server = app.listen(listenPort, (err) => {
if (err) {
logger.error({ err }, 'Unable to connect to MongoDB.')
throw err
}

logger.info('Listening on http://localhost:%s', listenPort)
})

server.on('upgrade', (request, socket, head) => {
wss.handleUpgrade(request, socket, head, function handleAuth(ws) {
// const jwtToken = new URL('http://localhost' + request.url).searchParams.get("token")
// TODO: check token and permissions
wss.emit('connection', ws, request)
})
})
8 changes: 4 additions & 4 deletions graphql/jest-mongodb-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module.exports = {
mongodbMemoryServerOptions: {
autoStart: false,
binary: {
version: '4.4.29'
version: '5.0.31',
},
instance: {
dbName: 'stylo-tests'
}
}
dbName: 'stylo-tests',
},
},
}
11 changes: 11 additions & 0 deletions graphql/migrations/20250305093600-mongo5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports.up = function (db) {
return db._run('executeDbAdminCommand', {
setFeatureCompatibilityVersion: '5.0',
})
}

exports.down = function (db) {
return db._run('executeDbAdminCommand', {
setFeatureCompatibilityVersion: '4.4',
})
}
Loading