mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Fix issue with sendBeacon request.
This commit is contained in:
parent
48db7708de
commit
17790aa5a8
6 changed files with 23 additions and 22 deletions
|
|
@ -3,11 +3,6 @@ import { getSession } from './session';
|
|||
import { getAuthToken } from './auth';
|
||||
import { unauthorized, badRequest, serverError } from './response';
|
||||
|
||||
const corsOptions = {
|
||||
origin: '*',
|
||||
credentials: true,
|
||||
};
|
||||
|
||||
export function createMiddleware(middleware) {
|
||||
return (req, res) =>
|
||||
new Promise((resolve, reject) => {
|
||||
|
|
@ -20,7 +15,7 @@ export function createMiddleware(middleware) {
|
|||
});
|
||||
}
|
||||
|
||||
export const useCors = createMiddleware(cors(corsOptions));
|
||||
export const useCors = createMiddleware(cors());
|
||||
|
||||
export const useSession = createMiddleware(async (req, res, next) => {
|
||||
let session;
|
||||
|
|
|
|||
|
|
@ -86,3 +86,11 @@ export async function getClientInfo(req, { screen }) {
|
|||
|
||||
return { userAgent, browser, os, ip, country, device };
|
||||
}
|
||||
|
||||
export function getJsonBody(req) {
|
||||
if (req.headers['content-type'].indexOf('text/plain') !== -1) {
|
||||
return JSON.parse(req.body);
|
||||
}
|
||||
|
||||
return req.body;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { getWebsiteByUuid, getSessionByUuid, createSession } from 'lib/queries';
|
||||
import { getClientInfo } from 'lib/request';
|
||||
import { getJsonBody, getClientInfo } from 'lib/request';
|
||||
import { uuid, isValidUuid, parseToken } from 'lib/crypto';
|
||||
|
||||
export async function getSession(req) {
|
||||
const { payload } = req.body;
|
||||
const { payload } = getJsonBody(req);
|
||||
|
||||
if (!payload) {
|
||||
throw new Error('Invalid request');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue