Skip to content

Conversation

@petersg83
Copy link
Contributor

@petersg83 petersg83 commented Apr 6, 2020

fix #4513

Description of what you did:

  • Split the config var server.admin.path in 2 vars server.admin.build.publicPath and server.admin.server.path
  • Change relative url paths to absolute url path using var server.admin.backend
  • Added a guide to setup strapi on a non-root url like mywebsite.com/mystrapi

I tried to spot everywhere it could break. Do not hesitate to heavily test, especially in the case you setup strapi on a non-root url.

@codecov
Copy link

codecov bot commented Apr 6, 2020

Codecov Report

Merging #5724 into features/media-lib will decrease coverage by 0.01%.
The diff coverage is 0.00%.

Impacted file tree graph

@@                  Coverage Diff                   @@
##           features/media-lib    #5724      +/-   ##
======================================================
- Coverage               19.16%   19.14%   -0.02%     
======================================================
  Files                     856      856              
  Lines                   11885    11897      +12     
  Branches                 1883     1889       +6     
======================================================
  Hits                     2278     2278              
- Misses                   8072     8078       +6     
- Partials                 1535     1541       +6     
Flag Coverage Δ
#front 14.48% <0.00%> (-0.02%) ⬇️
#unit 40.02% <ø> (ø)
Impacted Files Coverage Δ
...ntent-manager/admin/src/components/Inputs/index.js 0.00% <0.00%> (ø)
...rc/containers/EditViewDataManagerProvider/index.js 0.00% <0.00%> (ø)
.../containers/EditViewDataManagerProvider/reducer.js 0.00% <0.00%> (ø)
...ainers/EditViewDataManagerProvider/utils/schema.js 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a8c8efa...0c51f69. Read the comment docs.

@derrickmehaffy
Copy link
Member

derrickmehaffy commented Apr 6, 2020

I think I will move the guide part of this as I am currently writing deployment guides that include a proxy

Can merge with it like it is, and I'll just move it in my PR. Will test this in a bit.

Edit: Side note, please never ever recommend editing the default /etc/nginx/nginx.conf file for run the server from. Should always use virtual host files with Nginx.

@derrickmehaffy
Copy link
Member

derrickmehaffy commented Apr 6, 2020

So here are the 3 more popular use cases I see:

  1. both API and admin on sub-domain api.example.com/admin and api.example.com (this is what is mostly used now)
  2. both API and admin on sub-folder example.com/api/admin and example.com/api (what is most widely requested)
  3. Split API and admin on sub-folder example.com/admin and example.com/api (not as popular but has been requested)

@petersg83
Copy link
Contributor Author

Thanks for your feedback @derrickmehaffy, I will try to change the config file to only use 2 variables. @alexandrebodin proposes:

const configs = [
  /**
   * on the same domain
   */

  // => server located at http://www.my-app.com and admin at http://www.my-app.com/admin
  {
    server: {
      url: 'http://www.my-app.com',
    },
  },

  // => server located at http://www.my-app.com and admin at http://www.my-app.com/sub-path/admin
  {
    server: {
      url: 'http://www.my-app.com',
    },
    admin: {
      url: '/sub-path/admin'
    }
  },

  // => server located at http://www.my-app.com/sub-path and admin at http://www.my-app.com/sub-path/admin
  {
    server: {
      url: 'http://www.my-app.com/sub-path',
    },
    admin: {
      url: '/admin',
    },
  },

  // => server located at http://www.my-app.com/sub-path and admin at http://www.my-app.com/sub-path/dashboard
  {
    server: {
      url: 'http://www.my-app.com/sub-path',
    },
    admin: {
      url: '/dashboard',
    },
  },

  /**
   * on different domains
   */
  // => server located at http://api.my-app.com and admin at http://admin.my-app.com
  {
    server: {
      url: 'http://api.my-app.com',
    },
    admin: {
      url: 'http://admin.my-app.com',
    },
  },

  // => server located at http://api.my-app.com/sub-path and admin at http://admin.my-app.com
  {
    server: {
      url: 'http://api.my-app.com/sub-path',
    },
    admin: {
      url: 'http://admin.my-app.com',
    },
  },

  // => server located at http://api.my-app.com and admin at http://admin.my-app.com/sub-path
  {
    server: {
      url: 'http://api.my-app.com',
    },
    admin: {
      url: 'http://admin.my-app.com/sub-path',
    },
  },

  // => server located at http://api.my-app.com/sub-path and admin at http://admin.my-app.com/other-sub-path
  {
    server: {
      url: 'http://api.my-app.com/sub-path',
    },
    admin: {
      url: 'http://admin.my-app.com/other-sub-path',
    },
  },
];

@derrickmehaffy
Copy link
Member

Thanks for your feedback @derrickmehaffy, I will try to change the config file to only use 2 variables. @alexandrebodin proposes:

const configs = [
  /**
   * on the same domain
   */

  // => server located at http://www.my-app.com and admin at http://www.my-app.com/admin
  {
    server: {
      url: 'http://www.my-app.com',
    },
  },

  // => server located at http://www.my-app.com and admin at http://www.my-app.com/sub-path/admin
  {
    server: {
      url: 'http://www.my-app.com',
    },
    admin: {
      url: '/sub-path/admin'
    }
  },

  // => server located at http://www.my-app.com/sub-path and admin at http://www.my-app.com/sub-path/admin
  {
    server: {
      url: 'http://www.my-app.com/sub-path',
    },
    admin: {
      url: '/admin',
    },
  },

  // => server located at http://www.my-app.com/sub-path and admin at http://www.my-app.com/sub-path/dashboard
  {
    server: {
      url: 'http://www.my-app.com/sub-path',
    },
    admin: {
      url: '/dashboard',
    },
  },

  /**
   * on different domains
   */
  // => server located at http://api.my-app.com and admin at http://admin.my-app.com
  {
    server: {
      url: 'http://api.my-app.com',
    },
    admin: {
      url: 'http://admin.my-app.com',
    },
  },

  // => server located at http://api.my-app.com/sub-path and admin at http://admin.my-app.com
  {
    server: {
      url: 'http://api.my-app.com/sub-path',
    },
    admin: {
      url: 'http://admin.my-app.com',
    },
  },

  // => server located at http://api.my-app.com and admin at http://admin.my-app.com/sub-path
  {
    server: {
      url: 'http://api.my-app.com',
    },
    admin: {
      url: 'http://admin.my-app.com/sub-path',
    },
  },

  // => server located at http://api.my-app.com/sub-path and admin at http://admin.my-app.com/other-sub-path
  {
    server: {
      url: 'http://api.my-app.com/sub-path',
    },
    admin: {
      url: 'http://admin.my-app.com/other-sub-path',
    },
  },
];

Yup np and I agree this solution seems a bit more clear, once we get the structure in place I can assist in making some example configurations for Nginx on at least some of these. We will want to do some testing especially with something like:

example.com/apiendpoint + example.com/frontendfile.html as that sort of config would be very difficult to handle. My best guess would be to always recommend using something like example.com/api (admin doesn't matter since it's just an SPA with a single route, can but slid in anywhere, but generated routes are too dynamic)

@alexandrebodin
Copy link
Member

@derrickmehaffy using server.url we can remove the proxy btw *

@derrickmehaffy
Copy link
Member

@derrickmehaffy using server.url we can remove the proxy btw *

I'm fine with that, again I'd need to test this extensively (especially with the one-clicks)

Assuming since you would just prefix with http(s) and suffix with the port it should be fine, IP addresses should also work as well.

And should be no problems with using environment variables as to not have to statically define it for source control.

This of course would be a breaking change again. (Which I'm not against either, just need to document that)

@derrickmehaffy
Copy link
Member

@petersg83 don't forget we also need to remove the proxy docs from the server config https://strapi.io/documentation/3.0.0-beta.x/concepts/configurations.html#server

(and naturally move some documentation around, for now I'd say avoid putting any nginx proxy stuff directly in the docs as my PR: #5571 can supplement these)

Once I can get around to testing this I will start building some sample configs for the usecases

@petersg83 petersg83 marked this pull request as draft April 10, 2020 14:00
@petersg83
Copy link
Contributor Author

Yes no problem, it's still WIP :)

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>
@petersg83 petersg83 force-pushed the fix/#4513/AbilityToUseASubPathBehindAProxy branch from 258b490 to d1bb84a Compare April 10, 2020 15:39
Signed-off-by: Pierre Noël <pierre.noel@strapi.io>
@petersg83 petersg83 marked this pull request as ready for review April 10, 2020 16:24
…BehindAProxy

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>
@petersg83
Copy link
Contributor Author

I removed the guides I wrote so we can use yours :)
I forgot to --signoff some commits. I merged some branches in mine and I would prefer to avoid rewriting the history. Is it ok to accept without the DCO check or is there a solution I can use?

@derrickmehaffy
Copy link
Member

I'd say since you work for Strapi, signing off should be implied 😆 @alexandrebodin you da boss there.

@alexandrebodin
Copy link
Member

alexandrebodin commented Apr 10, 2020

Yeah I'm setting it to pass I don't think there will be any issue here 😂

- `admin`
- `autoOpen` (boolean): Enable or disabled administration opening on start. Default value: `true`.
- `path` (string): Allow to change the URL to access the admin panel. Default value: `/admin`.
- `url` (string): Url of your admin panel. Default value: `/admin`. Note: If the url is relative, it will be concatenate with `server.url`.
Copy link
Member

Choose a reason for hiding this comment

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

Combined with previous note

  • /admin
  • http://${host}:${port}/admin (to not have http://${host}:${port}/api/admin)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure of what you mean, especialy with to not have http://${host}:${port}/api/admin. Can you be more specific?

@derrickmehaffy
Copy link
Member

I will go over the proxy documentation in my PR with greater detail but the two notes I added should suffice for now.

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>
@petersg83 petersg83 force-pushed the fix/#4513/AbilityToUseASubPathBehindAProxy branch from 6e55458 to 76267a5 Compare April 14, 2020 09:56
Copy link
Member

@derrickmehaffy derrickmehaffy left a comment

Choose a reason for hiding this comment

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

LGTM, we just need to keep a reminder that whatever version this is included in that the migration guide needs to reflect the changes to the proxy block.

Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

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

Globally looks good. a few questions

email_confirmation: false,
email_confirmation_redirection: `http://${strapi.config.currentEnvironment.server.host}:${strapi.config.currentEnvironment.server.port}/admin`,
email_reset_password: `http://${strapi.config.currentEnvironment.server.host}:${strapi.config.currentEnvironment.server.port}/admin`,
email_confirmation_redirection: `${strapi.config.server.url}/admin`,
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be the admin url instead ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that would make sense

hostname,
port: strapi.config.port,
});
let serverUrl = _.trim(
Copy link
Member

Choose a reason for hiding this comment

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

This is kinda hard to read can split the logic and add some error messages when the urls are invalid. something like this

if (_.has(conf, 'server.url') {
  try {
  return  _.trim(new URL(conf.server.uril).toString())
 } catch (error) {
  throw new Error('Invalid server.url config. Make sure ....')
 }
}
---

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>
@derrickmehaffy
Copy link
Member

@alexandrebodin ? Making a new PR?

@alexandrebodin
Copy link
Member

@alexandrebodin ? Making a new PR?

Nope this was juste autoclosed because we delete the base branch. pierre is going to reopen it soon

@petersg83
Copy link
Contributor Author

Mmmh It looks like I'm stuck :p
I can't change the base (since it's closed I guess) and I can't reopen because the base doesn't exist anymore.

@derrickmehaffy
Copy link
Member

This pull request has been mentioned on Strapi Community Forum. There might be relevant details there:

https://forum.strapi.io/t/nginx-strapi-5802/1539/2

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.

4 participants