initial ws server with lookupToken

This commit is contained in:
Tim Olson
2023-08-28 20:25:49 -04:00
commit 2a0133e605
7 changed files with 341 additions and 0 deletions

25
main.js Normal file
View File

@@ -0,0 +1,25 @@
import 'dotenv/config'
import { createServer } from "http";
import { Server } from "socket.io"
import {lookupToken} from "./token.js";
const options = {}
if( process.env.DEXORDER_CORS )
options['cors'] = {origin:process.env.DEXORDER_CORS}
const httpServer = createServer()
const io = new Server(httpServer, options)
io.on("connection", (socket) => {
// initially, only anonymous messages are allowed
socket.on('lookupToken', (chainId, address, callback) => {
lookupToken(chainId, address).then((result)=>callback(result)).catch(()=>callback(null))
})
// todo send known tokens or other initial config
socket.emit('welcome', {})
});
const port = parseInt(process.env.DEXORDER_PORT) || 3000;
httpServer.listen(port)
console.log('Started server on port '+port)
console.log(options)