|
@@ -116,6 +116,9 @@ const server = http.createServer(async (req, res) => {
|
|
|
|
|
|
|
|
const user = getRequestUser(req, url.pathname);
|
|
const user = getRequestUser(req, url.pathname);
|
|
|
if (isLoginAsset(url.pathname)) {
|
|
if (isLoginAsset(url.pathname)) {
|
|
|
|
|
+ if ((url.pathname === '/login' || url.pathname === '/register') && url.search) {
|
|
|
|
|
+ return redirect(res, url.pathname);
|
|
|
|
|
+ }
|
|
|
if ((url.pathname === '/login' || url.pathname === '/register') && user) return redirect(res, '/');
|
|
if ((url.pathname === '/login' || url.pathname === '/register') && user) return redirect(res, '/');
|
|
|
return await serveStatic(req, res, url);
|
|
return await serveStatic(req, res, url);
|
|
|
}
|
|
}
|
|
@@ -592,7 +595,12 @@ async function readJson(req) {
|
|
|
const chunks = [];
|
|
const chunks = [];
|
|
|
for await (const chunk of req) chunks.push(chunk);
|
|
for await (const chunk of req) chunks.push(chunk);
|
|
|
if (!chunks.length) return {};
|
|
if (!chunks.length) return {};
|
|
|
- return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
|
|
|
|
|
+ const raw = Buffer.concat(chunks).toString('utf8');
|
|
|
|
|
+ const contentType = String(req.headers['content-type'] || '').toLowerCase();
|
|
|
|
|
+ if (contentType.includes('application/x-www-form-urlencoded')) {
|
|
|
|
|
+ return Object.fromEntries(new URLSearchParams(raw).entries());
|
|
|
|
|
+ }
|
|
|
|
|
+ return JSON.parse(raw);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function sendJson(res, status, payload) {
|
|
function sendJson(res, status, payload) {
|