From fa155548112f629990685b87b817196a33729450 Mon Sep 17 00:00:00 2001 From: eric-burel Date: Wed, 9 Jun 2021 16:32:46 +0200 Subject: [PATCH] add readme --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ meteor-backend | 2 +- next-frontend | 2 +- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..a6613de --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# From Meteor to Next + +This repository demoes using a Vulcan Next frontend with a legacy Vulcan Meteor backend. +This is targeted at existing Vulcan application that needs a progressive migration. + +## Start the Meteor server + +```sh +cd ./meteor-backend +# Install if not yet done: meteor npm install +git checkout demo/with-next-frontend +meteor npm run start -- --port=3001 +``` + +## Start the Next frontend + +```sh +cd ./next-frontend +# Install if not yet done: yarn install +git checkout demo/with-meteor-backend +yarn run dev +``` + +## How it works + +### Frontend + +Top priority of this demo is to connect a Vulcan Next frontend to an existing Meteor backend. + +- Next.js Apollo client is configured to use Meteor's graphql endpoint, running on port 3001. This value is set in `next-frontend/.env.development`. +- Seed from Next.js is disabled in `next-frontend/src/api/seed.ts` (we suppose you handle this in Meteor directly) +- MONGO_URI is changed to connect to the Meteor DB. Technically, this is not necessary if you use Next only for frontend, but we still need this change this value to deactivate the demo mode that is automatically enabled when we detect you are using the demo database. +- useUser hook will rely on Meteor useCurrentUser under the hood in `next-frontend/src/components/user/hooks.ts` +- Changed `next-frontend/src/pages/login.tsx`, `next-frontend/src/pages/signup.tsx` and `next-frontend/src/components/layout/Footer.tsx` to use legacy hooks to connect to Meteor. NOTE: in a future iteration, we should abstract the Next.js version into hooks, to make this cleaner +- Define Apollo CORS so we can include crendentials in `meteor-backed/settings.json` +- TODO: cross-origin set-cookie are not working. We might need to update Vulcan to support this https://stackoverflow.com/questions/46288437/set-cookies-for-cross-origin-requests, https://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain/1188145#1188145 +In Vulcan, relevant file is: packages/vulcan-users/lib/server/mutations.js, it might need some additional headers/setup to work ok in production + + +### Full-stack = progressively use Next as your backend + +In the long run, the goal is to transition the Meteor backend to Next as well, using Next API routes. + +- Next is configured to use the same Mongo database as Meteor locally. To get the URL of the local Meteor database, run `meteor mongo -U`. It's most probably something like this: `mongodb://127.0.0.1:3002/meteor` +- TODO: in Next, configure Passport to authenticate users using the existing Mongo database from Meteor \ No newline at end of file diff --git a/meteor-backend b/meteor-backend index 1856f7a..bd67f68 160000 --- a/meteor-backend +++ b/meteor-backend @@ -1 +1 @@ -Subproject commit 1856f7a2e9995c42c711f1600a2ea57ab561a26e +Subproject commit bd67f687a14f78558d3faa5f00e114bf33080d88 diff --git a/next-frontend b/next-frontend index ac61f0a..e1e5674 160000 --- a/next-frontend +++ b/next-frontend @@ -1 +1 @@ -Subproject commit ac61f0aea25c7df2d006cbf31ffb343941b1616a +Subproject commit e1e567460dd4175b6be9953ad297b82751b3cbed