From 686f30ec8b826bba8f445f34174e5f144c06b3af Mon Sep 17 00:00:00 2001 From: Frederico Maia Date: Wed, 15 May 2024 15:41:20 -0300 Subject: [PATCH 1/4] Improve instructions for the NPM installer and enhance WebApp examples --- .../breaking-changes/index.md | 94 ++++++++++++++++--- 1 file changed, 81 insertions(+), 13 deletions(-) diff --git a/v3-docs/v3-migration-docs/breaking-changes/index.md b/v3-docs/v3-migration-docs/breaking-changes/index.md index cc247c79dc..8141bac412 100644 --- a/v3-docs/v3-migration-docs/breaking-changes/index.md +++ b/v3-docs/v3-migration-docs/breaking-changes/index.md @@ -37,21 +37,27 @@ Meteor 3.0 is now using Node v20. This means that if you have any dependencies o of Node v14, you will need to update them to be compatible with Node v20. -## NPM Installer +## NPM Installer Update -The npm installer has been updated. Use the following command to install Meteor: +The npm installer for Meteor has been changed. For the official release, you can install Meteor with this command: ```bash npx meteor ``` -or +While we’re in the Release Candidate phase, use: + +```bash +npx meteor@rc +``` + +or specify a version directly: ```bash npx meteor@ ``` -You should be using a node version >= 20.0.0, if you use in your CI/CD you should update it to use the latest version of Node. +Ensure you're using Node version 20.0.0 or higher, especially in your CI/CD workflows, to be compatible with the latest Meteor version. ## Call x CallAsync @@ -104,18 +110,16 @@ await Meteor.callAsync('otherMethod') // [!code highlight] ``` -## Changes in Webapp +## WebApp Switches to Express ::: tip -Webapp now uses Express under the hood. This means that you can use all the express features in your Meteor app. - -But if you did any customizations in the `WebApp` package, you should check if they are compatible with Express. +WebApp has switched to Express from Connect. This upgrade lets you use all the Express features in your Meteor app. +If you've customized the WebApp package before, please verify if those customizations work with Express. ::: - -The `webapp` package now exports this new properties: +The `webapp` package now exports these new properties: ```ts type ExpressModule = { @@ -149,7 +153,9 @@ export declare module WebApp { // import { WebApp } from 'meteor/webapp'; ``` -If you want to use express in your app, you can do it like this: +### Routes with WebApp and Express + +To add Express routes in your app, check out the [Express Guide](https://expressjs.com/en/guide/routing.html) and follow this example: ```js import { WebApp } from 'meteor/webapp'; @@ -172,9 +178,71 @@ import { WebApp } from 'meteor/webapp'; WebApp.handlers.get('/hello', (req, res) => { res.send('Hello World'); }); - ``` -Changed engine from connect to express and changed api naming to match express. See below: + +### Middlewares with WebApp and Express + +To include **Router-level** Express middleware in your app, check out the [Express Guide](https://expressjs.com/en/guide/using-middleware.html#middleware.router) and follow this example: + +```js +import { WebApp } from 'meteor/webapp'; + +const app = WebApp.express(); +const router = WebApp.express.Router(); + +// This middleware is executed every time the app receives a request +router.use((req, res, next) => { + console.log('Router-level - Time:', Date.now()); + next(); +}) + +// This middleware shows request info for any type of HTTP request to the /hello/:name path +router.use('/hello/:name', (req, res, next) => { + console.log('Router-level - Request URL:', req.originalUrl); + next(); +}, (req, res, next) => { + console.log('Router-level - Request Type:', req.method); + next(); +}) + +// mount the router on the app +app.use('/', router); + +WebApp.handlers.use(app); +``` + +To include **Application-level** Express middleware in your app, check out the [Express Guide](https://expressjs.com/en/guide/using-middleware.html#middleware.application) and follow this example: + +```js +import { WebApp } from 'meteor/webapp'; + +const app = WebApp.express(); +const router = WebApp.express.Router() + +// This middleware is executed every time the app receives a request +router.use((req, res, next) => { + console.log('Router-level - Time:', Date.now()); + next(); +}) + +// This middleware shows request info for any type of HTTP request to the /hello/:name path +router.use('/hello/:name', (req, res, next) => { + console.log('Router-level - Request URL:', req.originalUrl); + next(); +}, (req, res, next) => { + console.log('Router-level - Request Type:', req.method); + next(); +}) + +// mount the router on the app +app.use('/', router); + +WebApp.handlers.use(app); +``` + +### New API Names + +Having switched from Connect to Express, we updated API names to align with Express. See the details below: - `WebApp.connectHandlers.use(middleware)` is now `WebApp.handlers.use(middleware)` - `WebApp.rawConnectHandlers.use(middleware)` is now `WebApp.rawHandlers.use(middleware)` - `WebApp.connectApp` is now `WebApp.expressApp` From 6a344481b2b9a947ee9305808361a5c5d6e5a667 Mon Sep 17 00:00:00 2001 From: denihs Date: Wed, 15 May 2024 14:57:34 -0400 Subject: [PATCH 2/4] Update v3 docs --- v3-docs/docs/api/accounts.md | 18 ++++++++++++++++++ v3-docs/docs/api/collections.md | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/v3-docs/docs/api/accounts.md b/v3-docs/docs/api/accounts.md index e505003a6b..be3e1f80e8 100644 --- a/v3-docs/docs/api/accounts.md +++ b/v3-docs/docs/api/accounts.md @@ -17,6 +17,24 @@ login provider packages: `accounts-password`, `accounts-facebook`, Read more about customizing user accounts in the [Accounts](http://guide.meteor.com/accounts.html) article in the Meteor Guide. +### Accounts with Session Storage {# accounts-session-storage} + +By default, Meteor uses Local Storage to store, among other things, login tokens in your browser session. But, for some applications, it makes sense to use Session Storage instead. You can achieve this by adding this to your settings: + +```json +{ + // ... all other settings, + "public": { + // ... all your public settings + "packages": { + "accounts": { + "clientStorage": "session" + } + } + } +} +``` + Retrieves the user record for the current user from diff --git a/v3-docs/docs/api/collections.md b/v3-docs/docs/api/collections.md index 4fab3b7e92..e88f881665 100644 --- a/v3-docs/docs/api/collections.md +++ b/v3-docs/docs/api/collections.md @@ -1144,6 +1144,38 @@ option: You can pass any MongoDB valid option, these are just examples using certificates configurations. + +### Mongo Oplog Options + +> Oplog options were introduced in Meteor 2.15.1 +If you set the [`MONGO_OPLOG_URL`](https://docs.meteor.com/environment-variables.html#MONGO-OPLOG-URL) env var, Meteor will use MongoDB's Oplog to show efficient, real time updates to your users via your subscriptions. + +Due to how Meteor's Oplog implementation is built behind the scenes, if you have certain collections where you expect **big amounts of write operations**, this might lead to **big CPU spikes on your meteor app server, even if you have no publications/subscriptions on any data/documents of these collections**. For more information on this, please have a look into [this blog post from 2016](https://blog.meteor.com/tuning-meteor-mongo-livedata-for-scalability-13fe9deb8908), [this github discussion from 2022](https://github.com/meteor/meteor/discussions/11842) or [this meteor forums post from 2023](https://forums.meteor.com/t/cpu-spikes-due-to-oplog-updates-without-subscriptions/60028). + +To solve this, **2 Oplog settings** have been introduced **to tweak, which collections are *watched* or *ignored* in the oplog**. + +**Exclusion**: To *exclude* for example all updates/inserts of documents in the 2 collections called `products` and `prices`, you would need to set the following setting in your Meteor settings file: + +```json + "packages": { + "mongo": { + "oplogExcludeCollections": ["products", "prices"] + } + } +``` + +**Inclusion**: vice versa, if you only want to watch/*include* the oplog for changes on documents in the 2 collections `chats` and `messages`, you would use: + +```json + "packages": { + "mongo": { + "oplogIncludeCollections": ["chats", "messages"] + } + } +``` + +For obvious reasons, using both `oplogExcludeCollections` and `oplogIncludeCollections` at the same time is not possible and will result in an error. + ### Mongo.setConnectionOptions(options) You can also call `Mongo.setConnectionOptions` to set the connection options but From a26fe8ecc53d152b79ea9915be49c2423bb51ec0 Mon Sep 17 00:00:00 2001 From: denihs Date: Wed, 15 May 2024 15:00:10 -0400 Subject: [PATCH 3/4] Update v3 docs to fix link --- v3-docs/docs/api/accounts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v3-docs/docs/api/accounts.md b/v3-docs/docs/api/accounts.md index be3e1f80e8..8724746678 100644 --- a/v3-docs/docs/api/accounts.md +++ b/v3-docs/docs/api/accounts.md @@ -17,7 +17,7 @@ login provider packages: `accounts-password`, `accounts-facebook`, Read more about customizing user accounts in the [Accounts](http://guide.meteor.com/accounts.html) article in the Meteor Guide. -### Accounts with Session Storage {# accounts-session-storage} +### Accounts with Session Storage {#accounts-session-storage} By default, Meteor uses Local Storage to store, among other things, login tokens in your browser session. But, for some applications, it makes sense to use Session Storage instead. You can achieve this by adding this to your settings: From 56aa1bb059ef8f9f841d1048af88bdc7e8613199 Mon Sep 17 00:00:00 2001 From: denihs Date: Wed, 15 May 2024 15:03:08 -0400 Subject: [PATCH 4/4] Update v3 docs: add mongo oplog options link --- v3-docs/docs/api/collections.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v3-docs/docs/api/collections.md b/v3-docs/docs/api/collections.md index e88f881665..90f8f3d892 100644 --- a/v3-docs/docs/api/collections.md +++ b/v3-docs/docs/api/collections.md @@ -1145,7 +1145,7 @@ You can pass any MongoDB valid option, these are just examples using certificates configurations. -### Mongo Oplog Options +### Mongo Oplog Options {#mongo-oplog-options} > Oplog options were introduced in Meteor 2.15.1 If you set the [`MONGO_OPLOG_URL`](https://docs.meteor.com/environment-variables.html#MONGO-OPLOG-URL) env var, Meteor will use MongoDB's Oplog to show efficient, real time updates to your users via your subscriptions.