Skip to main content

Setup

info

When you initialize any flavor of Lens that uses WASM it will run checks to make sure that SharedArrayBuffer is availiable
If everything is set correctly you will see following messages in your console: SIMD available: true Threads available: true

Check out our example

  1. Next to your index.html create server.js
  2. Copy following code to your server.js:
const http = require("http");
const fs = require("fs").promises;
const host = "localhost";
const port = 3000;
const typeMap = {
html: "text/html",
css: "text/css",
js: "text/javascript",
wasm: "application/wasm",
};

const requestListener = function (req, res) {
let url = req.url;
if (url === "/") url = "/index.html";
for (const [key, value] of Object.entries(typeMap)) {
if (url.endsWith(key)) res.setHeader("Content-Type", value);
}

fs.readFile(__dirname + url)
.then((contents) => {
res.setHeader("Cross-Origin-Opener-Policy", "same-origin"); // Cross origin isolation headers
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
res.writeHead(200);
res.end(contents);
})
.catch((err) => {
console.log("error: ", url);
console.log("Error", err.stack);
console.log("Error", err.name);
console.log("Error", err.message);
res.writeHead(500);
return;
});
};

const server = http.createServer(requestListener);
server.listen(port, host, () => {
console.log(`Server is running on http://${host}:${port}`);
});

info

To test Lens For Web on mobile device use HTTPS and SSL (Mobile devices don't provide acces to cameras via http)

  1. Install local-ssl-proxy npm install -g local-ssl-proxy
  2. Create certificates for localhost (for example with mkcert)
  3. Put certificates to your project folder
  4. Run proxy with your ports npx local-ssl-proxy --key localhost-key.pem --cert localhost.pem --source 3001 --target 3000
  5. Go to https://localhost:3001 from your mobile device