Skip to content

Commit

Permalink
refactor: fix UI in datetime picker and fix nestproxymiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
mrrishimeena committed Sep 23, 2024
1 parent 13d9167 commit f70a066
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 65 deletions.
64 changes: 19 additions & 45 deletions lib/errsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Errsole.koaProxyMiddleware = function (url) {
}
});
};

Errsole.nestExpressProxyMiddleware = function (path, req, res, next) {
const options = {
hostname: 'localhost',
Expand All @@ -126,57 +127,30 @@ Errsole.nestExpressProxyMiddleware = function (path, req, res, next) {
proxyRes.pipe(res, { end: true });
});

proxyReq.on('error', (err) => {
res.status(500).send('Proxy request error' + err);
});

if (req.method === 'POST' && req.body) {
const bodyData = JSON.stringify(req.body);
proxyReq.setHeader('Content-Type', 'application/json');
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
proxyReq.write(bodyData);
}

proxyReq.end();
req.pipe(proxyReq, { end: true });
};

Errsole.nestFastifyProxyMiddleware = function (path, req, res) {
const bodyChunks = [];
req.raw.on('data', chunk => {
bodyChunks.push(chunk);
});

req.raw.on('end', () => {
const bodyData = Buffer.concat(bodyChunks).toString();
const options = {
hostname: 'localhost',
port: this.port,
path: req.url.replace(path, ''),
method: req.method,
headers: {
...req.headers,
host: 'localhost:' + this.port
}
};

const proxyReq = http.request(options, (proxyRes) => {
if (proxyRes.statusCode && proxyRes.headers) {
res.raw.writeHead(proxyRes.statusCode, proxyRes.headers);
}
proxyRes.pipe(res.raw, { end: true });
});

proxyReq.on('error', (err) => {
res.status(500).send('Proxy request error: ' + err);
});
const options = {
hostname: 'localhost',
port: this.port,
path: req.url.replace(path, ''),
method: req.method,
headers: {
...req.headers,
host: 'localhost:' + this.port
}
};

if (req.method === 'POST' && bodyData) {
proxyReq.setHeader('Content-Type', 'application/json');
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
proxyReq.write(bodyData);
const proxyReq = http.request(options, (proxyRes) => {
if (proxyRes.statusCode && proxyRes.headers) {
res.raw.writeHead(proxyRes.statusCode, proxyRes.headers);
}
proxyReq.end();
proxyRes.pipe(res.raw, { end: true });
});

// Pipe the incoming request directly to the proxy request
req.raw.pipe(proxyReq, { end: true });
};

Errsole.hapiProxyMiddleware = function (basePath, auth = false) {
Expand Down
2 changes: 0 additions & 2 deletions lib/main/server/utils/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ SlackService.sendAlert = async function (message, type, messageExtraInfo, errsol
if (data && data.item) {
const parsedValue = JSON.parse(data.item.value);
if (parsedValue.status === false) {
console.log('Slack integration is disabled.');
return false; // Slack integration is disabled
}
// create alert url
Expand Down Expand Up @@ -154,7 +153,6 @@ EmailService.sendAlert = async function (message, type, messageExtraInfo, errsol
if (data && data.item) {
const parsedValue = JSON.parse(data.item.value);
if (parsedValue.status === false) {
console.log('Email integration is disabled.');
return false; // Email integration is disabled
}
// create alert url
Expand Down
11 changes: 6 additions & 5 deletions lib/web/assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ body {
margin-left: 10px;
}

.date-picker-date {
width: 120px !important;
.datetime-picker-date {
width: 125px !important;
}

.date-picker-time {
width: 120px !important;
.datetime-picker-time {
width: 125px !important;
margin-left: 10px !important;
}

.log-btn-apply {
Expand Down Expand Up @@ -314,7 +315,7 @@ body {
}

.filter-input-div {
width: calc(100% - 440px);
width: calc(100% - 445px);
}

.filter-input {
Expand Down
26 changes: 13 additions & 13 deletions lib/web/src/components/ConsoleLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as logActions from 'actions/logActions.js';
import * as appActions from 'actions/appActions.js';

/* Ante UI */
import { DatePicker, TimePicker, Layout, Input, Icon, Button, Collapse, Select, Spin, Switch, Modal, Tooltip, Menu, Dropdown, notification } from 'antd';
import { DatePicker, TimePicker, Layout, Icon, Button, Collapse, Select, Spin, Switch, Modal, Tooltip, Menu, Dropdown, notification, message } from 'antd';
const cookies = new Cookies();

const { Content } = Layout;
Expand Down Expand Up @@ -518,11 +518,11 @@ class ConsoleLogs extends React.Component {
});
}

handleDateChange(date, dateString) {
handleDateChange (date, dateString) {
this.setState({ searchDate: dateString }); // Save the formatted date string
}

handleTimeChange(time, timeString) {
handleTimeChange (time, timeString) {
this.setState({ searchTime: timeString }); // Save the formatted time string
}

Expand Down Expand Up @@ -860,22 +860,22 @@ class ConsoleLogs extends React.Component {
</Select>
</div>
<div className='filter float-l date-picker'>
<DatePicker
className='date-picker-date'
<DatePicker
className='datetime-picker-date'
placeholder='Select Date'
onChange={this.handleDateChange.bind(this)}
format='YYYY-MM-DD'
value={searchDate ? moment(searchDate) : null} // Set the selected date
value={searchDate ? moment(searchDate) : null}
/>
</div>
<div className='filter float-l date-picker'>
<div className='filter float-l time-picker'>
<TimePicker
className="time-picker-time"
placeholder="Select Time"
onChange={this.handleTimeChange.bind(this)}
format="HH:mm:ss"
value={searchTime ? moment(searchTime, 'HH:mm:ss') : null} // Set the selected time
/>
className='datetime-picker-time'
placeholder='Select Time'
onChange={this.handleTimeChange.bind(this)}
format='HH:mm:ss'
value={searchTime ? moment(searchTime, 'HH:mm:ss') : null}
/>
</div>
<div className='filter float-l log-btn-apply'>
<Button onClick={this.apply.bind(this)} type='primary'>Apply</Button>
Expand Down
1 change: 1 addition & 0 deletions lib/web/src/services/httpServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const URI = getBaseUri(); // Use the dynamic base URI
// Set axios defaults
axios.defaults.baseURL = URI;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.headers.patch['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.withCredentials = true;

// Setup Axios interceptors to attach the JWT
Expand Down

0 comments on commit f70a066

Please sign in to comment.