@@ -14,6 +14,7 @@ DB_PASSWORD=pikachu
|
|||||||
DB_TIMEZONE=Australia/Sydney
|
DB_TIMEZONE=Australia/Sydney
|
||||||
|
|
||||||
CHAT_URI=http://example.com:3200/chat
|
CHAT_URI=http://example.com:3200/chat
|
||||||
|
CHAT_KEY=chattychattybangbang
|
||||||
|
|
||||||
SESSION_SECRET=secret
|
SESSION_SECRET=secret
|
||||||
SESSION_ADMIN=adminsecret
|
SESSION_ADMIN=adminsecret
|
||||||
+14
-5
@@ -2,21 +2,30 @@ const fetch = require('node-fetch');
|
|||||||
const FormData = require('form-data');
|
const FormData = require('form-data');
|
||||||
|
|
||||||
const route = async (req, res) => {
|
const route = async (req, res) => {
|
||||||
|
if (!req.session.account) {
|
||||||
|
return status(403).send('No account detected');
|
||||||
|
}
|
||||||
|
|
||||||
//build the fake form data object
|
//build the fake form data object
|
||||||
let form = new FormData();
|
let form = new FormData();
|
||||||
form.append('username', req.session?.account?.username);
|
form.append('username', req.session?.account?.username);
|
||||||
|
form.append('key', process.env.CHAT_KEY);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//reserve the UUID with the chat server (hop 1)
|
//reserve the UUID with the chat server (hop 1)
|
||||||
const result = await fetch(`http://${process.env.CHAT_URI}/reserve`, { method: 'POST', body: form });
|
const result = await fetch(`http://${process.env.CHAT_URI}/reserve`, { method: 'POST', body: form });
|
||||||
|
|
||||||
const json = await result.json();
|
if (result.status == 200) {
|
||||||
res.cookie('pseudonym', json.pseudonym);
|
const json = await result.json();
|
||||||
res.status(200).send({ ok: true });
|
res.cookie('pseudonym', json.pseudonym);
|
||||||
|
res.status(200).send({ ok: true });
|
||||||
|
} else {
|
||||||
|
throw await result.text();
|
||||||
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error('Chat server not found');
|
console.error(`Chat server error: ${e}`);
|
||||||
res.cookie('pseudonym', '.null');
|
res.cookie('pseudonym', '.null');
|
||||||
res.status(200).send({ ok: false, error: 'Chat server not found' });
|
res.status(200).send({ ok: false, error: `Chat server error ${e}` });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user