The server for the Squeegee Whiteboard application
To start the server: npm start
.
To lint the code: npm run lint
.
To start the dev server (auto reload on code change): npm run dev
.
To insert debug messages, use the debug package: https://github.com/visionmedia/debug. Essentially:
const Debug = require('debug');
const debug = Debug('your:tag:here');
// ...
debug('debug message');
And then run the dev server (or regular server, using npm start
) with:
DEBUG=your:tag:here npm run dev
to get only debug messages from that specific tag.
Alternatively, to get debug messages from all tags use: DEBUG=* npm run dev
. For more
info, see the above link to the debug project on github.
Currently uses port 3000
by default.
- POST - /auth/register
- POST - /auth/login
-
PATCH - /changeUser/username
-
PATCH - /changeUser/email
-
PATCH - /changeUser/password
-
GET - /changeUser/info
-
POST - /changeBoard/create
-
PATCH - /changeBoard/name
-
PUT - /changeBoard/addMember
-
DELETE - /changeBoard/delete
-
GET - /boardInfo/owned
-
GET - /boardInfo/member
-
GET - /boardInfo/isMember
These endpoints don't require an auth token, but will return one. It should be stored in the browser's local storage. Example using axios (common js request library):
axios.post('http://localhost:3000/loginUser', {
email,
password,
}).then((response) => {
localStorage.setItem('JWT', response.data.token);
});
Registers a new user. Email must be unique. Returns your auth token on success.
POST request to the endpoint url.
Ex: localhost:3000/auth/register
JSON object in the form:
{
"email": <email>,
"password": <password in plaintext>,
"username": <username>
}
Ex:
{
"email": "joel@squeegee.xyz",
"password": "hunter2",
"username": "cool joe"
}
JSON object in the form:
{
"success": true,
"token": <json auth token>,
"message": <success message>
}
Ex:
{
"success": true,
"token": "JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwicGFzc3dv",
"message": "User successfully created."
}
JSON object in the form:
{
"success": false,
"message": <failure message>
}
{
"success": false,
"message": "Email is already in use."
}
Logs the user in. Returns your auth token on success.
POST request to the endpoint url.
Ex: localhost:3000/auth/login
JSON object in the form:
{
"email": <email>,
"password": <password in plaintext>
}
Ex:
{
"email": "joel@squeegee.xyz",
"password": "hunter2"
}
JSON object in the form:
{
"success": true,
"token": <json auth token>,
"message": <success message>
}
Ex:
{
"success": true,
"token": "JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwicGFzc3dv",
"message": "User logged in."
}
JSON object in the form:
{
"success": false,
"message": <failure message>
}
{
"success": false,
"message": "Incorrect email or password."
}
These endpoints require the auth token acquired through register or login.
Auth token is included in the request headers.
Ex: Authorization
JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwicGFzc3dv
Example using axios (common js request library):
const authToken = localStorage.getItem('JWT');
await axios.get('http://localhost:3000/updateUsername', {
params: {
username: newUsername,
},
headers: { Authorization: `JWT ${authToken}` },
});
Changes the user's name. Requires a user's auth token in the message header.
PATCH request to the endpoint url.
Ex: localhost:3000/changeUser/username
JSON object in the form:
{
"username": <username you want to change to>
}
Ex:
{
"username": "joel"
}
JSON object in the form:
{
"success": true,
"message": <success message>
}
Ex:
{
"success": true,
"message": "Username updated."
}
JSON object in the form:
{
"success": false,
"message": <failure message>
}
{
"success": false,
"message": "Invalid auth token."
}
Changes the user's email. Requires a user's auth token in the message header.
PATCH request to the endpoint url.
Ex: localhost:3000/changeUser/email
JSON object in the form:
{
"email": <email you want to change to>
}
Ex:
{
"email": "joel@squeegee.xyz"
}
JSON object in the form:
{
"success": true,
"message": <success message>
}
Ex:
{
"success": true,
"message": "Email updated."
}
JSON object in the form:
{
"success": false,
"message": <failure message>
}
{
"success": false,
"message": "Invalid auth token."
}
Changes the user's password. Requires a user's auth token in the message header.
PATCH request to the endpoint url.
Ex: localhost:3000/changeUser/password
JSON object in the form:
{
"oldPassword": <password changing from>,
"newPassword": <password changing to>
}
Ex:
{
"oldPassword": "hunter2",
"newPassword": "letmein"
}
JSON object in the form:
{
"success": true,
"message": <success message>
}
Ex:
{
"success": true,
"message": "Password updated."
}
JSON object in the form:
{
"success": false,
"message": <failure message>
}
{
"success": false,
"message": "Failed to update password."
}
Gets the logged in user's username and email address. Does not get password, since passwords aren't even stored as plaintext.
GET request to the endpoint url.
Ex: `localhost:3000/changeUser/info'
JSON object in the form:
{
"success": true,
"message": <success message>,
"username": <user's username>,
"email": <user's email>
}
Ex:
{
"success": true,
"message": "Successfully retrieved user info.",
"username": "JollyJoel",
"email": "joel@email.com"
}
JSON object in the form:
{
"success": false,
"message": <failure message>
}
{
"success": false,
"message": "Failed to retrieve owned boards"
}
Creates a board and adds the creating user as an owner.
POST request to the endpoint url.
Ex: localhost:3000/changeBoard/create
JSON object in the form:
{
"name": <board name>
}
Ex:
{
"name": "ex name"
}
JSON object in the form:
{
"success": true,
"message": <success message>,
"board_id": <base64 board identifier string>,
"board_preview": <svg text>
}
Ex:
{
"success": true,
"message": "Board created.",
"board_id": "dhohohi32y948234",
"board_preview": "... svg text ...",
}
JSON object in the form:
{
"success": false,
"message": <failure message>
}
{
"success": false,
"message": "Failed to create board."
}
Creates a board and adds the creating user as an owner.
Any member or admin can change a board name.
PATCH request to the endpoint url.
Ex: localhost:3000/changeBoard/name
JSON object in the form:
{
"name": <board name>,
"board_id": <base64 board identifier string>
}
Ex:
{
"name": "ex name",
"board_id": "askjdhqiuhiuqoij3920"
}
JSON object in the form:
{
"success": true,
"message": <success message>
}
Ex:
{
"success": true,
"message": "Board name updated."
}
JSON object in the form:
{
"success": false,
"message": <failure message>
}
{
"success": false,
"message": "Failed to update name."
}
Creates a board and adds the creating user as an owner.
PUT request to the endpoint url.
Ex: `localhost:3000/changeBoard/addMember'
JSON object in the form:
{
"board_id": <base64 board identifier string>
Ex:
{
"board_id": "iuhd929823h9dh2"
}
JSON object in the form:
{
"success": true,
"message": <success message>
}
Ex:
{
"success": true,
"message": "User added to board."
}
JSON object in the form:
{
"success": false,
"message": <failure message>
}
{
"success": false,
"message": "Failed to add user to board."
}
Creates a board and adds the creating user as an owner.
Any member or admin can delete a board.
POST request to the endpoint url.
Ex: `localhost:3000/changeBoard/delete'
JSON object in the form:
{
"board_id": <base64 board identifier string>
}
Ex:
{
"board_id": "kjshf2982u39823u"
}
JSON object in the form:
{
"success": true,
"message": <success message>
}
Ex:
{
"success": true,
"message": "Board deleted."
}
JSON object in the form:
{
"success": false,
"message": <failure message>
}
{
"success": false,
"message": "Failed to delete board."
}
Gets the list of boards owned by the user. If user owns no board, return empty list.
GET request to the endpoint url.
Ex: `localhost:3000/boardInfo/owned'
JSON object in the form:
{
"success": true,
"message": <success message>,
"boards": [
{
"board_id": <base64 board identifier string>,
"board_name": <board name>,
"board_preview": <svg text>,
},
...
]
}
Ex:
{
"success": true,
"message": "Successfully retrieved boards.",
"boards": [
{
"board_id": "sdaksjka2y92723h2dhui2d",
"board_name": "AwesomeBoard",
"board_preview": "... svg text ...",
},
{
"board_id": "dasdajdajkk28832",
"board_name": "secondBoard",
"board_preview": "... svg text ...",
}
]
}
JSON object in the form:
{
"success": false,
"message": <failure message>
}
{
"success": false,
"message": "Failed to retrieve owned boards"
}
Gets the list of boards the user is a member of. If user is not a member of any boards, return empty list.
Admin can see all boards.
GET request to the endpoint url.
Ex: `localhost:3000/boardInfo/member'
JSON object in the form:
{
"success": true,
"message": <success message>,
"boards": [
{
"board_id": <base64 board identifier string>,
"board_name": <board name>,
"board_preview": <svg text>,
},
...
]
}
Ex:
{
"success": true,
"message": "Successfully retrieved boards.",
"boards": [
{
"board_id": "asdsadaaggasdasd",
"board_name": "AwesomeBoard",
"board_preview": "... svg text ...",
},
{
"board_id": "safaf4f28282",
"board_name": "secondBoard",
"board_preview": "... svg text ...",
},
{
"board_id": "ferf343364436346",
"board_name": "Someone Else's Board",
"board_preview": "... svg text ...",
}
]
}
JSON object in the form:
{
"success": false,
"message": <failure message>
}
{
"success": false,
"message": "Failed to retrieve member boards"
}
Returns if a user is a member of a board or not.
Admin is considered member of all boards
GET request to the endpoint url.
Ex: localhost:3000/boardInfo/isMember
JSON object in the form:
{
"board_id": <base64 board identifier string>
}
Ex:
{
"board_id": "hd292898h239hd2"
}
JSON object in the form:
{
"success": true,
"message": <success message>,
"is_member": <true/false>
}
Ex:
{
"success": true,
"message": "Member found."
"is_member": true
}
JSON object in the form:
{
"success": false,
"message": <failure message>
}
{
"success": false,
"message": "Could not access API server."
}