Change listener.ts
This commit is contained in:
parent
25f50b1100
commit
8cd4f0b47b
19
listener.ts
19
listener.ts
|
@ -1,20 +1,22 @@
|
|||
import { run } from "@ludus/ludus-js-pure"
|
||||
|
||||
const port = Math.floor((Math.random() * 1000) + 50000)
|
||||
async function listen() {
|
||||
const port = Math.floor((Math.random() * 1000) + 50000)
|
||||
|
||||
const repl_info = { port }
|
||||
const repl_info = { port }
|
||||
|
||||
const repl_file = Bun.file("./.lrepl")
|
||||
const repl_file = Bun.file("./.lrepl")
|
||||
|
||||
await Bun.write(repl_file, JSON.stringify(repl_info))
|
||||
await Bun.write(repl_file, JSON.stringify(repl_info))
|
||||
|
||||
console.log(`Ludus REPL listening on localhost:${port}`)
|
||||
console.log(`Ludus REPL listening on localhost:${port}`)
|
||||
|
||||
Bun.listen({
|
||||
Bun.listen({
|
||||
hostname: "localhost",
|
||||
port,
|
||||
socket: {
|
||||
data: (socket, data) => {
|
||||
console.log("I got data!")
|
||||
const source = data.toString("utf-8")
|
||||
const result = run(source)
|
||||
const msgs = result.console
|
||||
|
@ -29,7 +31,10 @@ Bun.listen({
|
|||
},
|
||||
error: (socket, error) => { console.log(error); socket.end() }
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
await listen()
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user