initial ws server with lookupToken
This commit is contained in:
25
main.js
Normal file
25
main.js
Normal 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)
|
||||
Reference in New Issue
Block a user