Skip to content

Commit

Permalink
Merge pull request #3043 from LiteFarmOrg/release/3.5.2-b
Browse files Browse the repository at this point in the history
Patch 3.5.2 (only ngnix and logger changes)
  • Loading branch information
antsgar authored Dec 18, 2023
2 parents 81b239c + 393c705 commit e9d4117
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 13 deletions.
9 changes: 5 additions & 4 deletions packages/api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"uuid": "^8.3.0",
"winston": "^3.8.2",
"winston-daily-rotate-file": "^4.7.1",
"winston-transport": "4.6.0",
"xlsx-populate": "^1.21.0"
},
"devDependencies": {
Expand Down
43 changes: 40 additions & 3 deletions packages/api/src/common/logger.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import winston from 'winston';
import winston, { format } from 'winston';
import DailyRotateFile from 'winston-daily-rotate-file';
import Transport from 'winston-transport';
import * as Sentry from '@sentry/node';

const { errors, json, combine } = format;

// Add the error message as an enumerable property to return with res.json({ error })
const enumerateErrorMessage = format((info) => {
if (info instanceof Error) {
info.error = { message: info.message };
}
return info;
});

const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
format: combine(enumerateErrorMessage(), json()),
defaultMeta: { service: 'user-service' },
transports: [
//
Expand All @@ -23,11 +35,36 @@ const logger = winston.createLogger({
if (process.env.NODE_ENV !== 'production') {
logger.add(
new winston.transports.Console({
format: winston.format.simple(),
format: combine(errors(), json()),
}),
);
}

// Create custom transport for Sentry reporting
class SentryTransport extends Transport {
constructor(opts) {
super(opts);
}

log(info, callback) {
setImmediate(() => {
this.emit('logged', info);
});

// Only report if a true Error object
if (info instanceof Error) {
Sentry.captureException(info);
}

callback();
}
}

// Report Errors to Sentry
if (process.env.NODE_ENV !== 'development') {
logger.add(new SentryTransport());
}

console.log = (...args) => logger.info.call(logger, ...args);
console.info = (...args) => logger.info.call(logger, ...args);
console.warn = (...args) => logger.warn.call(logger, ...args);
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/controllers/cropVarietyController.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const cropVarietyController = {
const result = await CropVarietyModel.query().whereNotDeleted().where({ farm_id });
return res.status(200).send(result);
} catch (error) {
console.error(error);
return res.status(400).json({ error });
}
};
Expand All @@ -32,6 +33,7 @@ const cropVarietyController = {
? res.status(200).send(result)
: res.status(404).send('Crop variety not found');
} catch (error) {
console.error(error);
return res.status(400).json({ error });
}
};
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/controllers/documentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const documentController = {
.patch({ archived: req.body.archived });
return result ? res.sendStatus(200) : res.status(404).send('Document not found');
} catch (error) {
console.error(error);
return res.status(400).json({ error });
}
};
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/controllers/insightController.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const insightController = {
res.status(200).send({});
}
} catch (error) {
console.error(error);
res.status(400).json({ error });
}
};
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/controllers/managementPlanController.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ const managementPlanController = {
? res.status(200).send(removeCropVarietyFromManagementPlans(managementPlans))
: res.status(404).send('Field crop not found');
} catch (error) {
console.error(error);
res.status(400).json({ error });
}
};
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/controllers/organicHistoryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default {
const result = await OrganicHistoryModel.query().context(req.auth).insert(req.body);
return res.status(201).send(result);
} catch (error) {
console.error(error);
return res.status(400).json({ error });
}
};
Expand All @@ -36,6 +37,7 @@ export default {
? res.status(200).send(result)
: res.status(404).send('Organic history not found');
} catch (error) {
console.error(error);
return res.status(400).json({ error });
}
},
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/controllers/taskController.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ const taskController = {
}
return res.status(404).send('Tasks not found');
} catch (error) {
console.error(error);
return res.status(400).json({ error });
}
},
Expand Down Expand Up @@ -813,6 +814,7 @@ const taskController = {

return res.status(200).send(result);
} catch (error) {
console.error(error);
return res.status(400).json({ error });
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if (process.env.SENTRY_DSN && environment !== 'development') {
// Automatically instrument Node.js libraries and frameworks
...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
],

release: '3.5.2',
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
Expand Down
35 changes: 31 additions & 4 deletions packages/webapp/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ http {
client_max_body_size 20M;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Add MIME type for manifest.webmanifest
# See https://vite-pwa-org.netlify.app/deployment/nginx.html
types {
application/manifest+json webmanifest;
}
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
Expand All @@ -40,15 +45,37 @@ http {

server {
server_name beta.litefarm.org;
root /var/www/litefarm;

location = /index.html {
root /var/www/litefarm;
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
add_header Cache-Control "public, max-age=0, must-revalidate" always;
}

location = /manifest.webmanifest {
add_header Cache-Control "public, max-age=0, must-revalidate" always;
}

location = /sw.js {
add_header Cache-Control "public, max-age=0, must-revalidate" always;
}

# Set Cache-Control for various pwa-critical routes
# See https://vite-pwa-org.netlify.app/deployment/nginx.html#cache-control
location ^~ /assets/ {
add_header Cache-Control "public, max-age=31536000, s-maxage=31536000, immutable";
try_files $uri =404;
}

location ^~ /workbox- {
add_header Cache-Control "public, max-age=31536000, s-maxage=31536000, immutable";
try_files $uri =404;
}

location / {
root /var/www/litefarm;
try_files $uri /index.html;
autoindex off;
expires off;
add_header Cache-Control "public, max-age=0, s-maxage=0, must-revalidate" always;
try_files $uri /index.html =404;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/beta.litefarm.org/fullchain.pem; # managed by Certbot
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ if (import.meta.env.VITE_SENTRY_DSN) {
Sentry.init({
dsn: import.meta.env.VITE_SENTRY_DSN,
integrations: [new Integrations.BrowserTracing()],

release: '3.5.2',
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
Expand Down

0 comments on commit e9d4117

Please sign in to comment.