Running application example can be found on https://mroulette.herokuapp.com
git clone https://github.com/varvar/roulette.git
cd to folder roulette
npm install
npm update
npm start
Once server started it will be accessible on http://localhost:8080/
-
POST
-
{ "name":"User1", "email":"[email protected]", "password":"123456" }
Please note, that all properties are required and not optional
-
- Code: 200
Content:{ "id": 5, "name": "User1", "email": "[email protected]" }
- Code: 200
-
Email address is unique property and cannot be added twice.
-
POST
-
{ "email":"[email protected]", "password":"123456" }
Please note, that all properties are required and not optional
-
- Code: 200
Content:{ "code": 200, "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwibmFtZSI6InRlc3QyIiwiZW1haWwiOiJ0ZXN0MkBtYWlsLmNvbSIsInBhc3N3b3JkIjoiJDJiJDEwJGVLQVBBYXpWMm0wcDZyaHRFUVBvN082SnpES3F0cjd2UmhWZGFSaEE0Ry5KLnVIUGJVSW9LIiwiaXAiOm51bGwsImxhc3RMb2dpbiI6bnVsbCwibG9naW5Db3VudCI6bnVsbCwiY3JlYXRlZEF0IjoiMjAyMC0wNS0xMVQxMTo1OToxOS4wMDBaIiwidXBkYXRlZEF0IjoiMjAyMC0wNS0xMVQxMTo1OToxOS4wMDBaIiwiaWF0IjoxNTg5MTk4NDA2LCJleHAiOjE1ODkxOTg3MDZ9.tu27GFxtZJk-MjVgj5hMkPV7qnNoCoHmyJauV-Mmizk"
}
- Code: 200
-
Token returned in login response is JWT token and should be used for authentication in socket.io API
- User connection to socket API requires JWT token and socket server URL should look like this:
https://mroulette.herokuapp.com/?token={JWT token}
- Server emits everything to "messages" channel, so all connected users should listen to this channel.
Emit message to all users except sender
blast
Any type of messages as plain text
Emit message to a random user except sender
spin
Any type of messages as plain text
Emit a message to X random users except sender. X can be determined by the user. The default value in case it's not provided by user is 5.
wild
JSON as following:
{
"usersNumber":3,// number
"messsage": "Hello world" // any string
}
The only table is used in application is "users":
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) DEFAULT NULL,
`ip` varchar(255) DEFAULT NULL,
`last_login` datetime DEFAULT NULL,
`login_count` int(11) DEFAULT NULL,
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
"last_login","ip" and "login_count" are optional fields and used to provide additional info for user connected to socket. Those fields can be used for statistic information and for adding restrictions for IP addresses and login attempts.