Skip to content

Commit

Permalink
use vite
Browse files Browse the repository at this point in the history
  • Loading branch information
abentkamp committed Oct 28, 2023
1 parent 3c2d814 commit 9e95795
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/public/bin
96 changes: 96 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,102 @@
+49 211 81-12173<br />
</p>
</noscript>
<script>

const IO = {
_resolveGetLine: null,
_resolveRead: null,
_readPointer: null,
_nbytes: 0,
bufferStdIn : "",
putStrListeners: [],
listenPutStr(callback) {
this.putStrListeners.push(callback)
},
putStr(str) {
console.log('PUTSTR' + str)
str = str.split('\n')[2]
this.putStrListeners.forEach((listener) => {
listener(str)
})
},
async getLine() {
return new Promise((resolve, reject) => {
this._resolveGetLine = resolve
this.flushStdIn();
});
},
async read(ptr, nbytes) {
this._nbytes = nbytes
this._readPointer = ptr
return new Promise((resolve, reject) => {
this._resolveRead = resolve
this.flushStdIn();
});
},
flushStdIn() {
if(this._resolveGetLine) {
var lineBreak = this.bufferStdIn.indexOf("\n")
if (lineBreak != -1) {
this._resolveGetLine(stringToNewUTF8(this.bufferStdIn.substring(0,lineBreak+1)))
this.bufferStdIn = this.bufferStdIn.substring(lineBreak+1)
this._resolveGetLine = null
}
}
if(this._resolveRead) {
// console.log(`read: ${this.bufferStdIn}`)
stringToUTF8(this.bufferStdIn, this._readPointer, this._nbytes);
this._resolveRead()
this.bufferStdIn = ""
this._resolveRead = null
}
},
putLine(data) {
console.log("Client: ",data)
const str = data + '\r\n'
const byteLength = lengthBytesUTF8(str)
this.bufferStdIn += `Content-Length: ${byteLength}\r\n\r\n` + str
this.flushStdIn();
}
}


var input = ""
var i = 0;

function submit (ev) {
ev.preventDefault()
return false;
}

var stdoutBuffer = ""
var stderrBuffer = ""


var Module = {
"arguments": ["--worker"],
"preRun": function() {
function stdin() {
if (i < input.length) {
i++;
return input.charCodeAt(i);// Return ASCII code of character, or null if no input
} else {
return null
}
}

function stdout(asciiCode) {
stdoutBuffer += String.fromCharCode(asciiCode)
}

function stderr(asciiCode) {
stderrBuffer += String.fromCharCode(asciiCode)
}

FS.init(stdin, stdout, stderr);
}};
</script>
<script src="bin/lean.js"></script>
<script type="module" src="/client/src/index.tsx"></script>
</body>

Expand Down
13 changes: 13 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ export default defineConfig({
// svgr options
},
}),
{
name: "configure-response-headers",
configureServer: (server) => {
server.middlewares.use((_req, res, next) => {
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
next();
});
},
},
viteStaticCopy({
targets: [
{
Expand All @@ -22,6 +32,9 @@ export default defineConfig({
})],
publicDir: "client/public",
server: {
watch: {
ignored: "**/bin/**'"
},
port: 3000,
proxy: {
'/websocket': {
Expand Down

0 comments on commit 9e95795

Please sign in to comment.