Skip to content

Dev Server [beginner friendly] #4

@PaperPrototype

Description

@PaperPrototype

In order to get this working you'll need to make a svelte service worker and override the fetch event allowing import syntax to get files from OPFS (Origin Private File System).

We'll use a prefix like /opfsfiles/myfile (this way we don't interrupt normal server requests):

import { readFileContents } from "$lib/OPFS/FileUtils/Or/Something"

self.addEventListener('fetch', (event) => {

  // if the user wants a file from OPFS
  if (event.request.url.pathname.includes("/opfsfiles")) {
    const path = event.request.url.pathname.splice(10);
    const response = new Response(readFileContents(path))
    event.respondWith(response);
    return;
  }
        
  // normal server request
  event.respondWith(fetch(event.request));
})

Here is the original diagram from the slides:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions