1.0.2 • Published 11 months ago

content-selection-module v1.0.2

Weekly downloads
-
License
AGPL-3.0-or-later
Repository
-
Last release
11 months ago

Content-Selection-Component

This repo contains two custom 'content-selection' components for the Community Solid Server.

ContentSelectionRedirectHttpHandler

ContentSelectionRedirectHttpHandler uses redirects to point the client to the resource file that best matches the requested content type. The component is only active on specified paths and uses the specified type mappings to create HTTP redirects (3xx status plus location header). The ContentSelectionRedirectHttpHandler extends the HttpHandler class similar to the RedirectingHttpHandler.

  1. only HTTP GET
  2. only on specified server paths
  3. only file URIs without extension
  4. (optionally) only if match between accept header and type mappings

Example: GET 'accept: text/html' from /sensor-1/data -> 303 'location: /sensor-1/data.html' no content

ContentSelectionOperationHandler

ContentSelectionOperationHandler directly delivers the resource file that best matches the requested content type. The component is only active on specified paths and uses the specified type mappings to determine a URI with file extension which is then loaded from the ResourceStore. ContentSelectionOperationHandler extends the abstract OperationHandler class similar to the GetOperationHandler.

Conditions under which the ContentSelectionOperationHandler is active: 1. only HTTP GET 2. only on specified server paths 3. only file URIs without extension 4. only if the target resource does not exist

Example: GET 'accept: text/html' from /sensor-1/data -> 200 'location: /sensor-1/data.html' with file content

The ContentSelectionOperationHandler incompletely imitates the behavior of the Apache Module mod_negotiation.

Future Work

Conceptual:

Technical:

Setup

Install dependencies (CSS, components.js, Jest): npm i

Transpile TypeScript: npm run build

Start the ContentSelectionRedirectHttpHandler: npm run start:redirect

Start the ContentSelectionOperationHandler: npm run start:deliver

Run the tests (for ContentSelectionRedirectHttpHandler): npm test

CURL example: curl -v -H 'accept: text/html' http://localhost:3000/sensor-1/data

Use as NPM package

Clone CSS repo: git clone git@github.com:CommunitySolidServer/CommunitySolidServer.git

Add content-selection-module from NPM: npm i content-selection-module

Install CSS deps: npm i

Start CSS with a base and a content-selection config:
node ./bin/server.js -c config/file.json node_modules/content-selection-module/config/contentselection-redirect.json -f .data or npm start -- -c config/file.json ...

Bug?: Logs from the content-selection-module are not shown

Known Issues

  • Components.js can cause problems on Windows if the file path contains a whitespace

    • Example error Invalid term IRI WebAclMetadataCollector
  • Flexible config that can be combined with any other CSS config

    • Possible if CSS upgrades the componentsjs version to v5.5 or v6.0 (next major release)
    • Current workaround: add componentsjs@5.5.1 to dependencies of this package
1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago