27 lines
903 B
JavaScript
27 lines
903 B
JavaScript
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))
|
|
})
|
|
socket.on('address', (chainId, address) => loginAddress(socket, chainId, address) )
|
|
// 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)
|