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

[server] Allow specifying a basePath for a studio #720

Merged
merged 2 commits into from
Apr 8, 2018
Merged

Conversation

rexxars
Copy link
Member

@rexxars rexxars commented Apr 5, 2018

When building a studio for use outside of development and sanity.studio-context, you might want not want to host it at the root of a domain name. In order to allow for this, we need to:

  • Make the CLI tool build an index file containing paths to static files that is not always fixed to /static
  • Make the studio aware of the base path, prefixing the routes with it
  • Make it possible to customize the base path through configuration

This PR implements the above, and also (for consistency) makes the development server use the same base path. I felt this would make it easier to debug routing issues, among other things.

Using it is as simple as adding a basePath property under the project object in sanity.json:

{
  // ...
  "project": {
    "name": "Movies studio",
    "basePath": "/studio"
  },
  // ...
}

When you access / in a development environment and a base path is set, we need to redirect to the correct location. This is currently handled inside of @sanity/default-layout since it contains the root router, but we could consider moving this to the SanityRoot component in @sanity/base in order to ensure this is "always" applied regardless of layout. Thoughts?

Fixes #692

@rexxars rexxars requested a review from bjoerge April 5, 2018 15:26
Copy link
Member

@bjoerge bjoerge left a comment

Choose a reason for hiding this comment

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

LGTM!

@rexxars rexxars merged commit 4571f37 into next Apr 8, 2018
rexxars added a commit that referenced this pull request Apr 9, 2018
* [server] Allow specifying a basePath for a studio

* [default-layout] Resolve and use base path for studio if specified
@rexxars rexxars deleted the studio-base-path branch April 9, 2018 09:42
kristofferjs pushed a commit that referenced this pull request Apr 12, 2018
* [server] Allow specifying a basePath for a studio

* [default-layout] Resolve and use base path for studio if specified
kristofferjs pushed a commit that referenced this pull request Apr 12, 2018
* [form-builder] Conflicting name causes radiobuttons not to focus

* [components] Styling focus after selectContainer is removed

* [form-builder] Requests from PR

* [import] Support importing from folder

* [core] Allow importing datasets from directory

* [core] Improve `sanity dataset import` documentation

* [validation] Allow unicode in URIs

* [chore] Avoid mixed export/imports (#699)

* [image-url] Fix parsing image source (#728)

* [image-url] Fix parsing image source

* [image-url] Remove only from test case and change comprison operators to triple equal in parseSource

* [components] Styling focus state on select (#682)

* [server] Allow specifying a basePath for a studio (#720)

* [server] Allow specifying a basePath for a studio

* [default-layout] Resolve and use base path for studio if specified

* [image-url] Code style fixes

* v0.128.12

* [cli] Allow using template flag in interactive mode

* v0.128.13
bjoerge pushed a commit that referenced this pull request Apr 19, 2018
* [form-builder] Conflicting name causes radiobuttons not to focus

* [components] Styling focus after selectContainer is removed

* [form-builder] Requests from PR

* [import] Support importing from folder

* [core] Allow importing datasets from directory

* [core] Improve `sanity dataset import` documentation

* [validation] Allow unicode in URIs

* [chore] Avoid mixed export/imports (#699)

* [image-url] Fix parsing image source (#728)

* [image-url] Fix parsing image source

* [image-url] Remove only from test case and change comprison operators to triple equal in parseSource

* [components] Styling focus state on select (#682)

* [server] Allow specifying a basePath for a studio (#720)

* [server] Allow specifying a basePath for a studio

* [default-layout] Resolve and use base path for studio if specified

* [image-url] Code style fixes

* v0.128.12

* [cli] Allow using template flag in interactive mode

* v0.128.13
@dan-dr
Copy link
Contributor

dan-dr commented May 15, 2018

Hey I found out it'd be very useful if I could specify the basePath as an option in the build command, because it'll make it much easier to use in CI and build systems (my basePath is different in production/staging).

I found how to do it, will probably PR soon.

@@ -96,7 +97,7 @@ export default async (args, context) => {
const indexStart = Date.now()
spin = output.spinner('Building index document').start()
const doc = await getDocumentElement(
{...compilationConfig, hashes: chunkMap, project: config.get('project')},
Copy link
Contributor

@dan-dr dan-dr May 15, 2018

Choose a reason for hiding this comment

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

Regarding adding the ability to specify basePath as an option in the cli, I was thinking of using it like this:

    const doc = await getDocumentElement(
      {...compilationConfig, hashes: chunkMap},
      {
        basePath: flags.basePath || (project && project.basePath) || '',
        scripts: ['vendor.bundle.js', 'app.bundle.js'].map(asset => {
          const assetPath = absoluteMatch.test(asset) ? asset : `js/${asset}`
          return {
            path: assetPath,
            hash: chunkMap[assetPath] || chunkMap[asset]
          }
        })
      }
    )

where somewhere before you do const project = config.get('project')

@dan-dr
Copy link
Contributor

dan-dr commented May 17, 2018

maybe though it's better to have it in an environment variable?

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.

The studio can't run if not on the root domain
3 participants