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

initial implementation for configureServer #4903

Closed

Conversation

gautamsi
Copy link
Member

@gautamsi gautamsi commented Feb 20, 2021

closes #4902

@JedWatson @timleslie I am not sure if you want to call this function name differently (configureServer or configureExpress as in v5). initial try at this, hopefully this fixes the issue for trusting the proxy as well as enabling other scenarios like increasing payload size for graphql. I will add changeset if needed also this is very small change, so go ahead and fix this if you want to merge by changing few details.

This is needed to enable support for custom express server config. I need it to publish new fields based on TinyMCE and CKEditor5. I will have to use the configureServer method and as additional step to enable the field but we can use it until you guys figure out a way to let Fields access express instance and configure static path there.

@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2021

⚠️ No Changeset found

Latest commit: c94b577

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Feb 20, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/keystonejs/keystone-next-docs/8kgx6JWaoHBF9BgguRi9HtfNQf53
✅ Preview: https://keystone-next-git-fork-gautamsi-new-interface-trust-pro-8d2ea2.vercel.app

@vercel vercel bot temporarily deployed to Preview February 20, 2021 12:38 Inactive
@gautamsi gautamsi changed the title initial implement for configureExpress initial implementation for configureExpress Feb 20, 2021
@gautamsi gautamsi changed the title initial implementation for configureExpress initial implementation for configureServer Feb 20, 2021
@gautamsi gautamsi force-pushed the new-interface-trust-proxy branch from adf4a03 to d6def0e Compare February 20, 2021 12:53
@vercel vercel bot temporarily deployed to Preview February 20, 2021 12:53 Inactive
@gautamsi
Copy link
Member Author

@MurzNN has tested this and found that the value of trust proxy is being set but reverted somehow from verbose logs.

keystone-next dev
🤞 Starting Keystone
  express:application set "x-powered-by" to true +0ms
  express:application set "etag" to 'weak' +2ms
  express:application set "etag fn" to [Function: generateETag] +0ms
  express:application set "env" to 'development' +1ms
  express:application set "query parser" to 'extended' +0ms
  express:application set "query parser fn" to [Function: parseExtendedQueryString] +0ms
  express:application set "subdomain offset" to 2 +0ms
  express:application set "trust proxy" to false +0ms
  express:application set "trust proxy fn" to [Function: trustNone] +1ms
  express:application booting in development mode +0ms
  express:application set "view" to [Function: View] +0ms

gautamsi added a commit to keystonejs-contrib/keystonejs-contrib that referenced this pull request Feb 21, 2021
@vercel vercel bot temporarily deployed to Preview February 23, 2021 20:09 Inactive
Copy link
Contributor

@MurzNN MurzNN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #4902 is solved via other way, so seems 'trust proxy' is not necessary yet, but will be good to have it whatever.

@@ -52,5 +52,10 @@ export default auth.withAuth(
// // store: redisSessionStore({ client: redis.createClient() }),
// secret: sessionSecret,
// }),
server: {
configureServer(app) {
app.set('trust proxy', true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting trust proxy in this place give no effect seems because express is initialized earlier default values for serve Admin UI? Or maybe this is not enough to make session cookies working.

For investigate this we can enable verbose logging of express via starting DEBUG=express:* yarn dev and I see that this code is initialized later, that express startup. Even if I place console.log('configuring trust proxy'); in first line of examples-next/basic/keystone.ts file - it will be executed after initializing of express, here is output:

server: {
      configureServer(app) {
        console.log('CONFIGURING TRUST PROXY');
        app.set('trust proxy', true);
      }

The output is:

$ DEBUG=express:* yarn dev
yarn run v1.22.10
$ keystone-next dev
🤞 Starting Keystone
  express:application set "x-powered-by" to true +0ms
  express:application set "etag" to 'weak' +1ms
  express:application set "etag fn" to [Function: generateETag] +1ms
  express:application set "env" to 'development' +1ms
  express:application set "query parser" to 'extended' +0ms
  express:application set "query parser fn" to [Function: parseExtendedQueryString] +1ms
  express:application set "subdomain offset" to 2 +0ms
  express:application set "trust proxy" to false +0ms
  express:application set "trust proxy fn" to [Function: trustNone] +0ms
  express:application booting in development mode +0ms
  express:application set "view" to [Function: View] +0ms
  express:application set "views" to '/srv/korepov/domains/ks-t1.k.dev.digiterra.pro/src/keystone/examples-next/basic/views' +0ms
  express:application set "jsonp callback name" to 'callback' +1ms
CONFIGURING TRUST PROXY
  express:router use '/' query +3s
  express:router:layer new '/' +1ms
  express:router use '/' expressInit +1ms
  express:router:layer new '/' +0ms
  express:router use '/__keystone_dev_status' <anonymous> +0ms
  express:router:layer new '/__keystone_dev_status' +0ms
  express:router use '/' <anonymous> +1ms
  express:router:layer new '/' +0ms
⭐️ Dev Server Ready on http://localhost:3000
✨ Generating graphQL schema
✨ Connecting to the database
(node:3661400) DeprecationWarning: Listening to events on the Db class has been deprecated and will be removed in the next major version.
✨ Generating Admin UI code
✨ Creating server
  express:application set "x-powered-by" to true +1s
  express:application set "etag" to 'weak' +0ms
  express:application set "etag fn" to [Function: generateETag] +1ms
  express:application set "env" to 'development' +0ms
  express:application set "query parser" to 'extended' +0ms
  express:application set "query parser fn" to [Function: parseExtendedQueryString] +0ms
  express:application set "subdomain offset" to 2 +0ms
  express:application set "trust proxy" to false +1ms
  express:application set "trust proxy fn" to [Function: trustNone] +0ms
  express:application booting in development mode +0ms
  express:application set "view" to [Function: View] +0ms
  express:application set "views" to '/srv/korepov/domains/ks-t1.k.dev.digiterra.pro/src/keystone/examples-next/basic/views' +1ms
  express:application set "jsonp callback name" to 'callback' +0ms
✨ Preparing GraphQL Server
  express:router use '/' query +58ms

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And even more - this code seems isn't even called, because adding:

    server: {
      configureServer(app) {
        console.log('CONFIGURING TRUST PROXY');
        app.set('trust proxy', true);
      },
    },

gives no output of this line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may only work if you are using this branch

@vercel vercel bot temporarily deployed to Preview February 27, 2021 07:13 Inactive
@JedWatson
Copy link
Member

Hey @gautamsi sorry it's been so long, I wanted to get back to you with some feedback on this PR

I really like the API, and I see the importance of having this implemented. You've also designed it in a way that's consistent with similar config options which is great 👍

However, not too long ago we technically supported generating Keystone (both the Admin UI and the GraphQL API) as a Next.js app that could be deployed entirely to a Serverless environment like Vercel

I'm really keen to get back to that, which this moves us ever so slightly further away from.

Not saying that's a reason to block it, just that how the config options are set up really needs to be thought about comprehensively so they are clear for both use-cases.

The answer is probably that this config option can only coexist with another specifying that the server target is express (as opposed to nextjs or something similar)

We also need to carefully consider the lifecycle here -- is this configuration for the just-created app? or at some point in the middle of the configuration process? that gets super complex, as we've seen in previous keystone versions, and makes me more inclined to sidestep this entirely and make Keystone able to export its own middleware so you can drop it into your own app like Next.js does

Per my comment to @timleslie on #4912 I think we need to do some big picture config design, so we can confidently continue adding these features without accidentally conflicting with other planned changes; sorry that's delaying this, it's high on our list to get done but we're also putting most of our focus right now into documenting and cleaning up what's there as a starting point.

Until then this is on the radar but unlikely to get merged, until we've really thought it through and are confident we're not painting ourselves into a corner.

@JedWatson
Copy link
Member

Further to that previous comment, the other thing to consider (given the lifecycle of setting up an express app is so delicate) is that maybe we should be exposing more server config for things like trust proxy

Again, that's not a straight-forward "yes" for me, just wanted to highlight that we really need to do some big picture config design here around the various use cases.

@gautamsi
Copy link
Member Author

gautamsi commented Mar 1, 2021

@JedWatson thanks for clarifying the point. I had some chat with @timleslie on this. I agree that the new config scheme must be well thought per the future plan. I am also interested in serverless.

That said, you are also right that this kind of request will be more from community. We can work on creating layers which can have certain aspect, like:

  1. Have serverless export which can not support some of the feature like middleware and this PR.
  2. Export to middleware which can be plugged in the existing express app or have the keystone-next cli run it with middleware config including this kind of configuration support.

For now I am thinking of creating keystonejs-contrib cli which would allow options not supported by keystone-next cli and later migrate back to official one when ready.

@gautamsi
Copy link
Member Author

gautamsi commented Mar 8, 2021

@JedWatson @timleslie should we use this as experimental feature like #5033 (comment)

@stale
Copy link

stale bot commented Aug 10, 2021

It looks like there hasn't been any activity here in over 6 months. Sorry about that! We've flagged this issue for special attention. It wil be manually reviewed by maintainers, not automatically closed. If you have any additional information please leave us a comment. It really helps! Thank you for you contribution. :)

@gautamsi
Copy link
Member Author

gautamsi commented Sep 9, 2021

closing in favor of #6467

@gautamsi gautamsi closed this Sep 9, 2021
@gautamsi gautamsi deleted the new-interface-trust-proxy branch September 9, 2021 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keystone-next Admin UI refresh loop on nginx reverse proxy
5 participants