-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat: create await new ParseServer(config).startApp()
to resolve cloud code and schema before express app is exposed
#7914
Conversation
## [5.2.1-alpha.1](parse-community/parse-server@5.2.0...5.2.1-alpha.1) (2022-03-26) ### Bug Fixes * return correct response when revert is used in beforeSave ([parse-community#7839](parse-community#7839)) ([f63fb2b](parse-community@f63fb2b))
… Cloud Function validation (parse-community#7892)
## [5.2.1-alpha.2](parse-community/parse-server@5.2.1-alpha.1...5.2.1-alpha.2) (2022-03-26) ### Performance Improvements * reduce database operations when using the constant parameter in Cloud Function validation ([parse-community#7892](parse-community#7892)) ([48bd512](parse-community@48bd512))
# [5.3.0-alpha.1](parse-community/parse-server@5.2.1-alpha.2...5.3.0-alpha.1) (2022-03-27) ### Features * add MongoDB 5.1 compatibility ([parse-community#7682](parse-community#7682)) ([90155cf](parse-community@90155cf))
# [5.3.0-alpha.2](parse-community/parse-server@5.3.0-alpha.1...5.3.0-alpha.2) (2022-03-27) ### Bug Fixes * security upgrade parse push adapter from 4.1.0 to 4.1.2 ([parse-community#7893](parse-community#7893)) ([ef56e98](parse-community@ef56e98))
# [5.3.0-alpha.3](parse-community/parse-server@5.3.0-alpha.2...5.3.0-alpha.3) (2022-03-27) ### Features * add MongoDB 5.2 support ([parse-community#7894](parse-community#7894)) ([6b4b358](parse-community@6b4b358))
Thanks for opening this pull request!
|
Codecov ReportBase: 94.21% // Head: 85.04% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## alpha #7914 +/- ##
==========================================
- Coverage 94.21% 85.04% -9.18%
==========================================
Files 182 182
Lines 13733 13762 +29
==========================================
- Hits 12939 11704 -1235
- Misses 794 2058 +1264
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Restarted failed tests |
# [5.3.0-alpha.4](parse-community/parse-server@5.3.0-alpha.3...5.3.0-alpha.4) (2022-04-04) ### Bug Fixes * custom database options are not passed to MongoDB GridFS ([parse-community#7911](parse-community#7911)) ([a72b384](parse-community@a72b384))
I think this might close #7527 |
await new ParseServer(config).startApp()
await new ParseServer(config).startApp()
await new ParseServer(config).startApp()
await new ParseServer(config).startApp()
to resolve cloud code and schema before express app is exposed
It’s a bit of everything really. And yep, I believe the race condition is fixed by this PR. @Moumouls might have more to say though |
Perfect, it was also a point that I planned to check to support correctly serverless env. Here I only have one question; if you expose the app port AFTER the migration/init/serverStartComplete, what happens if a developer uses the Parse JS SDK into these functions (before/after migration, startServerComplete). From my knowledge, if I remember correctly the Parse JS SDK onboarded on parse-server use the "serverUrl" to interact with parse-server. So a developer could be blocked (also if he use the rest/graphql api in these functions). To avoid this issue on my side for serverless env, I found that the we should introduce a new "publicPort" option like the "publicServerUrl" to fix the issue, and only expose parse-server to external traffic once it's ready. We should not use a "directAccess" strategy, since developers could use GraphQL API or the REST API in these initialization functions. If you confirm with a test that Parse JS SDK (or rest call, or Graphql call) query into before/after migration /startServerComplete fails, your changes will be a breaking change. And we will need to add a new "publicPort" to expose the completely initialized parse-server to the external traffic. Tell what do you think about this @dblythy 🙂 |
async createDeleteSession() { | ||
const session = new Parse.Session(); | ||
await session.save(null, { useMasterKey: true }); | ||
await session.destroy({ useMasterKey: true }); | ||
const { response } = await rest.create(this.config, Auth.master(this.config), '_Session', {}); | ||
await rest.del(this.config, Auth.master(this.config), '_Session', response.objectId); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Owww I see here @dblythy that you encountered the error since the SDK uses the port.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the old code should not be changed, if the old code works, any Parse SDK/GraphQL/REST call during the init will work.
The old code works fine because the core tests don’t care for race conditions / deploying schema before exposure and checking cloud code, and use the current function ParseServer.start. This results in Parse mounting on its express app as soon as it’s created so any endpoint is available, before schemas, cloud code etc, which is problematic in envs which re-scale often. If you have a beforeSave or beforeFind hook that ensures data security and Parse exposes that route before the trigger is registered, then it can lead to big leaks if new instances are regularly deployed. This new feature isn’t a breaking change as existing functionality works fine, if you want Parse Server to wait to init before your express app you can Any JS SDK methods will only work when .listen is called, but if someone is going to the effort to use My thoughts is that there isn’t any downside to the new function, there will be some improvements to be made for sure but I don’t see why it can’t operate as is alongside the current implementation. Anyone who would implement it would be aware that the server won’t be available until they mount it with express. |
Yes but the new start-up strategy will not expose parse-server port until startServerComplete for example. In my case for example I've some Rest/GraphQL calls during serverStartComplete to seed/perform DB checks before exposing the app. Also, users that want to use the before/afterMigration function and try to request some data will be blocked. Parse Server historically has 2 serverUrl properties, one for public traffic, and another one for internal traffic. serverUrl and publicServerUrl. I think we can introduce the same strategy with "publicPort" You can easily call listen 2 times on express app :) before/afterMigration, serverStartComplete function without the possibility to call Parse REST/GraphQL/SDK API seems useless to me. Also, you can test the breaking change by trying to call a Parse.Query into the serverStartComplete. it should fail currently. |
Could you give an example? Does this mean you want to be able to call the Parse Server API before the server has finished its start-up procedure? |
59215e6
to
e6d7d8f
Compare
I'm not quite sure how this is at all possible in the current version, considering in order to call the Parse API the public routes have to be available, and To circumvent this, I have added a Parse Server option const config = {
...
holdPublicRoutes: true,
}
const parseServer = await new ParseServer(config).startApp();
const app = express();
app.use('/parse', parseServer);
const server = app.listen(12701);
await longStartupMethod();
parseServer.mountPublicRoutes(); // any client API calls before this will return unauthorized: master key is required |
@dblythy @mtrezza I apologize. I think I found the misunderstanding here 🙂 From the beginning, on my side, I was talking about the The static start method should be maybe refactored/deprecated in favor of a static async start, to only listen once the server is initialized. The developers can await the start or use serverStartComplete. I use the static start method on my projects combined with serverStartComplete: ex: https://github.com/Moumouls/parse-next-mono-starter/blob/65d2a9e6d485185c1164619e17d64d4d45034d88/packages/back/src/server.ts#L75 I was also wrong to want parse-server to be able to handle readiness by itself. I think we should not implement options like Finally, sorry for the wasted time here. I can suggest removing the From the static start and startAsync method the events should occur in this order from my point of view:
Then we should be good to go 🚀 |
There are two sides to readiness:
For (1) we already have the the For (2) I don't think Parse Server should handle any type of request until is has started up, unless we want to implement a distinct "start-up" API, which would likely be a more complex discussion and I don't think is currently part of this discussion. More generally, polling Parse Server for readiness is actually a somewhat outdated technique. The start-of-the-art mechanism would be to launch Parse Server with a configuration of hooks that are called once it's ready / failed / etc, and then the load balancer starts sending requests, restarts or replaces the instance. Also in this case, readiness management is very much within the scope of Parse Server. |
I think Parse Server should provide sufficient tools to handle a graceful start. But for example, PM2 can send traffic once it detects a I think the core problem is how to allow developers to use SDK/REST/GQL API in before/after migration and serverStartComplete function given that these functions should be called BEFORE Or developers need to start a custom express app, with a dedicated port to handle on their side the graceful start with their related business logic ? |
I'm not sure what's pending here or what the general feedback was. This approach covers the following objectives:
|
Closing as this will be introduced as a breaking change in V6. |
New Pull Request Checklist
Issue Description
Currently, there is no way to use cloud code if you are using ES Modules due to the fact that
import
needs to be async.Related issue: #7560
Closes: #7527, #7560
Approach
Adds
await new ParseServer().startApp()
that create a Parse Server asynchronously so that a developer using ES imports and schemas can be sure that their cloud triggers and schemas are registered before creating the express app.TODOs before merging