revert conversion of join to XHR call

This commit is contained in:
AlecM33
2022-01-21 01:33:49 -05:00
parent 422bffd95b
commit 4e4aee3fe8
3 changed files with 113 additions and 144 deletions

View File

@@ -19,7 +19,7 @@ const apiLimiter = rateLimit({
const corsOptions = process.env.NODE_ENV.trim() === 'development'
? {
origin: '*',
optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
optionsSuccessStatus: 200
}
: {
origin: 'https://playwerewolf.uk.r.appspot.com',
@@ -27,7 +27,7 @@ const corsOptions = process.env.NODE_ENV.trim() === 'development'
};
router.use(cors(corsOptions));
router.options('/:code/players', cors(corsOptions)); // enable pre-flight request for DELETE
//router.options('/:code/players', cors(corsOptions));
if (process.env.NODE_ENV.trim() === 'production') { // in prod, limit clients to creating 5 games per 10 minutes.
router.use('/create', apiLimiter);
@@ -65,21 +65,21 @@ router.get('/:code/availability', function (req, res) {
});
});
router.patch('/:code/players', function (req, res) {
if (
req.body === null
|| req.body.cookie === null
|| (typeof req.body.cookie !== 'string' && req.body.cookie !== false)
|| (req.body.cookie.length !== globals.USER_SIGNATURE_LENGTH && req.body.cookie !== false)
) {
res.status(400).send();
}
gameManager.joinGame(req.body.cookie, req.params.code).then((data) => {
res.status(200).send(data);
}).catch((code) => {
res.status(code).send();
});
});
// router.patch('/:code/players', function (req, res) {
// if (
// req.body === null
// || req.body.cookie === null
// || (typeof req.body.cookie !== 'string' && req.body.cookie !== false)
// || (req.body.cookie.length !== globals.USER_SIGNATURE_LENGTH && req.body.cookie !== false)
// ) {
// res.status(400).send();
// }
// gameManager.joinGame(req.body.cookie, req.params.code).then((data) => {
// res.status(200).send(data);
// }).catch((code) => {
// res.status(code).send();
// });
// });
router.get('/environment', function (req, res) {
res.status(200).send(gameManager.environment);