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

Ability to bundle and serve additional static files #160

Closed
simonw opened this issue Nov 30, 2017 · 8 comments
Closed

Ability to bundle and serve additional static files #160

simonw opened this issue Nov 30, 2017 · 8 comments

Comments

@simonw
Copy link
Owner

simonw commented Nov 30, 2017

Since we now have custom templates, we should support including custom static files with them as well. Maybe something like this:

datasette mydb.db --template-dir=templates/ --static-dir=static/

This should also be supported by datasette publish - see also #157

@simonw simonw added this to the Custom templates edition milestone Nov 30, 2017
@simonw
Copy link
Owner Author

simonw commented Dec 1, 2017

Question is... what should happen to the default static stuff? At the moment that's just https://fivethirtyeight.datasettes.com/-/static/app.css - though I want to improve that to include a content hash, see #154

@simonw simonw changed the title Ability to bundle additional static files Ability to bundle and serve additional static files Dec 2, 2017
@simonw
Copy link
Owner Author

simonw commented Dec 2, 2017

This is about more than just CSS and JavaScript - there are plenty of reasons someone might want to bundle HTML as well, e.g. for building something like https://sf-tree-search.now.sh/

So, instead of thinking about this in terms of /static/, I'm going to think about this in terms of allowing people to mount one or more document roots (or docroots).

datasette serve mydb.db -d my-doc-root/

This will cause the root of the server to show content from the my-doc-root/ directory (assuming it has an index.html file in it).

A more common option will be to mount specific folders to specific directories, like this:

datasette serve mydb.db -d static:my-static/

Now any hits to /static/foo.css will serve content from my-static/foo.css

@simonw
Copy link
Owner Author

simonw commented Dec 2, 2017

Not sure which I like better out of -d/--docroot or -s/--static or -m/--mount for this.

@simonw
Copy link
Owner Author

simonw commented Dec 2, 2017

-m is already taken for --metadata.

simonw added a commit that referenced this issue Dec 3, 2017
You can now tell Datasette to serve static files from a specific location at a
specific mountpoint.

For example:

	datasette serve mydb.db --static extra-css:/tmp/static/css

Now if you visit this URL:

	http://localhost:8001/extra-css/blah.css

The following file will be served:

	/tmp/static/css/blah.css

Refs #160
@simonw
Copy link
Owner Author

simonw commented Dec 3, 2017

You can now tell Datasette to serve static files from a specific location at a
specific mountpoint.

For example:

datasette serve mydb.db --static extra-css:/tmp/static/css

Now if you visit this URL:

http://localhost:8001/extra-css/blah.css

The following file will be served:

/tmp/static/css/blah.css

@simonw
Copy link
Owner Author

simonw commented Dec 3, 2017

Still TODO: teach datasette publish and friends about this.

simonw added a commit that referenced this issue Dec 9, 2017
Example usage:

    datasette package --static css:extra-css/ --static js:extra-js/ \
    	sf-trees.db --template-dir templates/ --tag sf-trees --branch master

This creates a local Docker image that includes copies of the templates/,
extra-css/ and extra-js/ directories. You can then run it like this:

	docker run -p 8001:8001 sf-trees

For publishing to Zeit now:

	datasette publish now --static css:extra-css/ --static js:extra-js/ \
		sf-trees.db --template-dir templates/ --name sf-trees --branch master

Example: https://sf-trees-wbihszoazc.now.sh/sf-trees-02c8ef1/Street_Tree_List

For publishing to Heroku:

	datasette publish heroku --static css:extra-css/ --static js:extra-js/ \
		sf-trees.db --template-dir templates/ --branch master

Closes #157, #160
@simonw simonw closed this as completed Dec 9, 2017
@simonw
Copy link
Owner Author

simonw commented Dec 9, 2017

Example usage:

datasette package --static css:extra-css/ --static js:extra-js/ \
	sf-trees.db --template-dir templates/ --tag sf-trees --branch master

This creates a local Docker image that includes copies of the templates/,
extra-css/ and extra-js/ directories. You can then run it like this:

docker run -p 8001:8001 sf-trees

For publishing to Zeit now:

datasette publish now --static css:extra-css/ --static js:extra-js/ \
	sf-trees.db --template-dir templates/ --name sf-trees --branch master

Example: https://sf-trees-wbihszoazc.now.sh/sf-trees-02c8ef1/Street_Tree_List

For publishing to Heroku:

datasette publish heroku --static css:extra-css/ --static js:extra-js/ \
	sf-trees.db --template-dir templates/ --branch master

psychemedia added a commit to psychemedia/jupyter-datasette-proxy that referenced this issue Feb 2, 2019
@psychemedia
Copy link
Contributor

psychemedia commented Feb 2, 2019

Do you have any simple working examples of how to use --static? Inspection of default served files suggests locations such as http://example.com/-/static/app.css?0e06ee.

If datasette is being proxied to http://example.com/foo/datasette, what form should arguments to --static take so that static files are correctly referenced?

Use case is here: https://github.com/psychemedia/jupyterserverproxy-datasette-demo Trying to do a really simple datasette demo in MyBinder using jupyter-server-proxy.

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

No branches or pull requests

2 participants