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

Add a "static site" handler to serve resources from a camliRoot #1579

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

angelcabo
Copy link
Contributor

@angelcabo angelcabo commented Dec 12, 2021

Addresses #1275

This PR adds a static site app handler to enable serving static web resources, like a single page app, from a configured camliRoot node.

Once you configure the handler, you can "install" the app by uploading the files to a camliRoot.

Build everything:
$ go run make.go

Start the app:
$ devcam server

Upload the app's source files:
$ pk-put file --permanode --title='Static App Source' ./test-app-source

Make the source permanode a camliRoot:
$ pk-put attr --add [last permanode sha from previous output] camliRoot "Static App Source"

Note: You can also configure a search root for the app handler to enable searching via the app route:
pk-put permanode --title='Test App Search Root'

This will add search support to the app's endpoint while limiting queries to the nodes contained in the specified search root:

$ curl -X POST http://localhost:3179/static-app/search -d' { "expression" : "is:image", "describe": {} } '

Finally, add the static app prefix configuration to your server's config:

"/static-app/": {
	"handler": "app",
	"enabled": ["_env", "${CAMLI_STATICAPP_ENABLED}"],
	"handlerArgs": {
		"prefix": "/static-app/",
		"serverListen": "localhost:3179",
		"program": "staticapp",
		"appConfig": {
			"staticRoot": "Static App Source",
			"searchRoot": "Test App Search Root"
		}
	}
}

And restart the server:
$ devcam server -staticapp

You should be able to now visit your static app at the app prefix hosted by your Perkeep server.

Screen Shot 2021-12-12 at 11 32 07 AM

@aviau
Copy link
Member

aviau commented Mar 13, 2022

Hey, that looks pretty cool.

Looking at this, I am thinking of the following:

  • We should rename the current fs package to fuse.
  • We should create an fs package that implements io.FS on top of a fetcher (and/or client).
  • Your app should use that new package, probably with http.FileServer.

The io.FS implementation will surely be useful for other things.

I'd be willing to help with some of that work if you also agree that it makes sense.

@angelcabo
Copy link
Contributor Author

@aviau I think that's an interesting idea. Do you think the idea would be that this new implementation could eventually replace the pk-mount backend? I know that's built with fuse, but I'm not sure if the implementations would align well. I took a cursory glance at the mount code and it seems like that uses a 3rd party FS interface for emulating the filesystem. Maybe we would just keep them separate, but I could see some overlap between the filesystem emulation currently built in the existing fuse package, and whatever would be added to this proposed fs package. What are your thoughts?

@angelcabo
Copy link
Contributor Author

In other words, I hadn't thought about it until your comment, but maybe it would have made more sense if I had initially used the existing CamliFileSystem implementation via NewRootedCamliFileSystem to fetch static files, rather than using my own lookup implementation and schema.NewFileReader directly. Had I done that, is there still value in wrapping the existing CamliFileSystem behind the new io/fs abstraction interfaces? Would it make sense to just make the existing CamliFileSystem implement the io/fs interfaces? Or does it still make sense to you to start fresh and let the fuse-specific filesystem implementation sit alongside some new filesystem abstraction layer?

@angelcabo
Copy link
Contributor Author

Actually, on further thought, it probably doesn't make sense to try to make the existing CamliFileSystem conform both to a io/fs implementation and a fuse.FS implementation given the interfaces overlap in conflicting ways. Rather, a new filesystem abstraction built with the io/fs package could possibly be used as an implementation detail by the existing fuse-based CamliFileSystem, but regardless would be separate from the existing fuse package.

@aviau
Copy link
Member

aviau commented Mar 21, 2022

ways. Rather, a new filesystem abstraction built with the io/fs package could possibly be used as an implementation detail by the existing fuse-based CamliFileSystem, but regardless would be separate from the existing fuse package.

Yes, exactly.

The current FUSE package should eventually be switch to a user of the FS interface. If we implement io/fs we can get WebDAV almost for free too, and that would help mac users since basil no longer supports macos.

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.

None yet

2 participants