isoserver
v1.1.2
Published
A tool for WebContainers so you can create webservers without a need to connect to an external server.
Downloads
10
Readme
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 theget
andpost
functions. (This is going to be fixed very soon) - You can only use the
get
andpost
methods. - Relative URLs only work on HTML tags that support
href
andsrc
, and also only forfetch
. XMLHttpRequest does not work yet. req
argument does not supportparams
yet