1.1.2 • Published 1 year ago

isoserver v1.1.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

isoserver

A tool for WebContainers so you can create webservers without a need to connect to an external server.

Usage

Step 1: Inject to WebContainer

Here's how to inject to a WebContainer:

let server = new IsoServer();
let frame = document.querySelector('#my_iframe');

let container = await WebContainer.boot();
let process = await container.spawn('node', ['index.js']);
server.inject(process, iframe);

Step 2: The code inside 'index.js'

Here's the code that you should put inside index.js:

let IsoServer = require('isoserver');
let server = new IsoServer();

server.get("/", () => {
    return `<h1> Hello! </h1>
    <a href="/next_page"> Click here to navigate to a different page. </a>`;
})

server.get("/next_page", () => {
    return `<h1> Hello again! </h1>
    <a href="/"> Click here to go back </a>`;
})

server.post("/base_64", (req) => {
    return btoa(req);
})

server.listen();

Uses

I don't see much use for this, other than when you're offline. For example, let's say you want to use a web server, but you're online. This could be a fix.

Limitations

This project is in its first update, so it's very unfinished.

  • You can only run Vanilla JavaScript code inside of the function, as it cannot connect to an external server. require() will not work in the get and post functions. (This is going to be fixed very soon)
  • You can only use the get and post methods.
  • Relative URLs only work on HTML tags that support href and src, and also only for fetch. XMLHttpRequest does not work yet.
  • req argument does not support params yet
1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago