2020-04-14 08:25:58 +02:00
|
|
|
import getConfig from 'next/config';
|
|
|
|
|
2020-08-03 16:31:20 +02:00
|
|
|
const { serverRuntimeConfig } = getConfig() || {};
|
2020-06-13 11:46:20 +02:00
|
|
|
const { nodeEnv } = serverRuntimeConfig || {};
|
2020-05-19 07:50:16 +02:00
|
|
|
|
2020-04-12 18:27:01 +02:00
|
|
|
export const getIp = (req: any) => {
|
|
|
|
if (!req || !req.headers) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
const forwarded = req.headers['x-forwarded-for'];
|
|
|
|
const before = forwarded
|
|
|
|
? forwarded.split(/, /)[0]
|
|
|
|
: req.connection.remoteAddress;
|
2020-04-14 08:25:58 +02:00
|
|
|
const ip = nodeEnv === 'development' ? '1.2.3.4' : before;
|
2020-04-12 18:27:01 +02:00
|
|
|
return ip;
|
|
|
|
};
|
|
|
|
|
2020-05-01 14:08:30 +02:00
|
|
|
export const getErrorMsg = (error: any[] | string): string => {
|
2021-06-01 22:20:29 +02:00
|
|
|
console.log(error);
|
|
|
|
if (!error) return 'Unknown Error';
|
|
|
|
if (typeof error === 'string') return error;
|
|
|
|
if (error[2]?.err?.details) return error[2]?.err?.details;
|
|
|
|
if (error[1]) return error[1];
|
2020-04-12 18:27:01 +02:00
|
|
|
|
2021-06-01 22:20:29 +02:00
|
|
|
return 'Unkown Error';
|
2020-04-12 18:27:01 +02:00
|
|
|
};
|