Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Add a comment #163

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
037ca4d
add new relic
nvhoanganh Feb 7, 2022
c694207
remove dotenv and update dockerfile
nvhoanganh Feb 8, 2022
1a4b24a
remove dotenv
nvhoanganh Feb 8, 2022
5df0349
report errors
nvhoanganh Feb 8, 2022
d724f98
Removed the buggy code
nvhoanganh Feb 8, 2022
86ac2f0
push another error
nvhoanganh Feb 9, 2022
7b05709
making another change here
nvhoanganh Feb 9, 2022
b499b0c
added Git Ignore
nvhoanganh Feb 14, 2022
8d84e73
test commit
Feb 14, 2022
73bab93
WFER-2 Add New Relic browser agent (#1)
nvhoanganh Feb 15, 2022
551712b
throw error when there are more than 10 items in the cart
nvhoanganh Feb 15, 2022
2d937d4
remove error
nvhoanganh Feb 15, 2022
410baf0
Merge branch 'master' of https://github.com/nvhoanganh/front-end
nvhoanganh Feb 15, 2022
2d13d40
if more than 10 then not allowed (#2)
nvhoanganh Feb 15, 2022
0dc7ea4
test PR in IDE (#3)
nvhoanganh Feb 16, 2022
95344f8
revert back to normal
nvhoanganh Feb 17, 2022
05fff1a
testcommit (#4)
maci0 Feb 18, 2022
aac4698
add commit
nvhoanganh Feb 18, 2022
2ad180a
add error to master (#5)
nvhoanganh Feb 18, 2022
dd7d9e3
remove errors and add winston logger
nvhoanganh Feb 18, 2022
402d340
use newrelic logger
nvhoanganh Feb 18, 2022
4feabeb
update script
nvhoanganh Feb 18, 2022
4be1583
inject error
nvhoanganh Feb 22, 2022
e0fd9ac
fix typo
nvhoanganh Feb 22, 2022
84afd71
add log
nvhoanganh Feb 22, 2022
a18aef4
update the bash file
nvhoanganh Feb 22, 2022
5ce4749
remove error
nvhoanganh Feb 22, 2022
42c3cb3
add new readme
nvhoanganh Feb 23, 2022
426ae3b
inject some exception
nvhoanganh Feb 23, 2022
802b15f
someone removed the error line
nvhoanganh Feb 23, 2022
46e8c7c
Add cors
nvhoanganh Feb 25, 2022
6e1aa88
inject error
nvhoanganh Mar 3, 2022
3f50cd8
Add Ramda
nvhoanganh Jul 21, 2022
383514d
add a comment
nvhoanganh Nov 22, 2022
2d6ac0b
add newrelic config
nvhoanganh May 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@
# Ignore coverage reports
/coverage

.idea
.idea

.DS_Store

newrelic_agent.log

agentlog.log
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM node:10-alpine
FROM node:12-alpine
ENV NODE_ENV "production"
ENV PORT 8079
EXPOSE 8079
ENV NEW_RELIC_NO_CONFIG_FILE=true
RUN addgroup mygroup && adduser -D -G mygroup myuser && mkdir -p /usr/src/app && chown -R myuser /usr/src/app

# Prepare app directory
Expand Down
1 change: 1 addition & 0 deletions NewReadme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Front-end app
---
Front-end application written in [Node.js](https://nodejs.org/en/) that puts together all of the microservices under [microservices-demo](https://github.com/microservices-demo/microservices-demo).
Front-end application written in [Node.js](https://nodejs.org/en/) that puts together all of the microservices under [microservices-demo](https://github.com/microservices-demo/microservices-demo)

# Build

Expand Down Expand Up @@ -36,8 +36,6 @@ Front-end application written in [Node.js](https://nodejs.org/en/) that puts tog

## Node

`npm install`

## Docker

`make test-image`
Expand All @@ -56,6 +54,8 @@ Front-end application written in [Node.js](https://nodejs.org/en/) that puts tog
make test
```

`npm install`

## End-to-End tests:

To make sure that the test suite is running against the latest (local) version with your changes, you need to manually build
Expand Down Expand Up @@ -96,3 +96,7 @@ make e2e
# Push

`GROUP=weaveworksdemos COMMIT=test ./scripts/push.sh`

this is new changes

some changes
8 changes: 7 additions & 1 deletion api/cart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,21 @@
// Update cart item
app.post("/cart/update", function (req, res, next) {
console.log("Attempting to update cart item: " + JSON.stringify(req.body));

if (req.body.id == null) {
next(new Error("Must pass id of item to update"), 400);
return;
}

if (req.body.quantity == null) {
next(new Error("Must pass quantity to update"), 400);
return;
}

if (parseInt(req.body.quantity) > 20) {
throw new Error("Cannot have quantity more than 20");
}

var custId = helpers.getCustomerId(req, app.get("env"));

async.waterfall([
Expand Down
19 changes: 19 additions & 0 deletions helpers/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { pipe, map, path, filter, head, mergeDeepLeft } = require("ramda");

const getAuthor = (id) => pipe(
path(["result", "authors"]),
filter(item => item.id === id),
head
);

const getJoin = (data) =>
pipe(
path(["result", "books"]),
map(item =>
mergeDeepLeft(item, getAuthor(item.author)(data))
)
)(data);

module.exports = {
getJoin
}
53 changes: 36 additions & 17 deletions helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
(function (){
(function () {
'use strict';

var request = require("request");
var newrelic = require("newrelic");
var helpers = {};

const winston = require('winston');
const newrelicFormatter = require('@newrelic/winston-enricher');
helpers.logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.json(),
// combine with newrelic enricher
newrelicFormatter()
),
defaultMeta: { service: 'front-end' },
transports: [
// just push to console this will be picked up by Newrlic k8s infra agent
new winston.transports.Console()
],
});


/* Public: errorHandler is a middleware that handles your errors
*
* Example:
Expand All @@ -12,24 +30,25 @@
* app.use(helpers.errorHandler);
* */

helpers.errorHandler = function(err, req, res, next) {
helpers.errorHandler = function (err, req, res, next) {
var ret = {
message: err.message,
error: err
error: err
};
newrelic.noticeError(err);
res.
status(err.status || 500).
send(ret);
};

helpers.sessionMiddleware = function(err, req, res, next) {
if(!req.cookies.logged_in) {
helpers.sessionMiddleware = function (err, req, res, next) {
if (!req.cookies.logged_in) {
res.session.customerId = null;
}
};

/* Responds with the given body and status 200 OK */
helpers.respondSuccessBody = function(res, body) {
helpers.respondSuccessBody = function (res, body) {
helpers.respondStatusBody(res, 200, body);
}

Expand All @@ -39,24 +58,24 @@
* statusCode - the HTTP status code to set to the response
* body - (string) the body to yield to the response
*/
helpers.respondStatusBody = function(res, statusCode, body) {
helpers.respondStatusBody = function (res, statusCode, body) {
res.writeHeader(statusCode);
res.write(body);
res.end();
}

/* Responds with the given statusCode */
helpers.respondStatus = function(res, statusCode) {
helpers.respondStatus = function (res, statusCode) {
res.writeHeader(statusCode);
res.end();
}

/* Rewrites and redirects any url that doesn't end with a slash. */
helpers.rewriteSlash = function(req, res, next) {
if(req.url.substr(-1) == '/' && req.url.length > 1)
res.redirect(301, req.url.slice(0, -1));
else
next();
helpers.rewriteSlash = function (req, res, next) {
if (req.url.substr(-1) == '/' && req.url.length > 1)
res.redirect(301, req.url.slice(0, -1));
else
next();
}

/* Public: performs an HTTP GET request to the given URL
Expand All @@ -75,15 +94,15 @@
* });
* });
*/
helpers.simpleHttpRequest = function(url, res, next) {
request.get(url, function(error, response, body) {
helpers.simpleHttpRequest = function (url, res, next) {
request.get(url, function (error, response, body) {
if (error) return next(error);
helpers.respondSuccessBody(res, body);
}.bind({res: res}));
}.bind({ res: res }));
}

/* TODO: Add documentation */
helpers.getCustomerId = function(req, env) {
helpers.getCustomerId = function (req, env) {
// Check if logged in. Get customer Id
var logged_in = req.cookies.logged_in;

Expand Down
52 changes: 52 additions & 0 deletions newrelic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';
/**
* New Relic agent configuration.
*
* See lib/config/default.js in the agent distribution for a more complete
* description of configuration variables and their potential values.
*/
exports.config = {
/**
* Array of application names.
*/
app_name: ['sock-shop-frontend'],
/**
* Your New Relic license key.
*/
logging: {
/**
* Level at which to log. 'trace' is most useful to New Relic when diagnosing
* issues with the agent, 'info' and higher will impose the least overhead on
* production applications.
*/
level: 'info'
},
/**
* When true, all request headers except for those listed in attributes.exclude
* will be captured for all traces, unless otherwise specified in a destination's
* attributes include/exclude lists.
*/
allow_all_headers: true,
attributes: {
/**
* Prefix of attributes to exclude from all destinations. Allows * as wildcard
* at end.
*
* NOTE: If excluding headers, they must be in camelCase form to be filtered.
*
* @env NEW_RELIC_ATTRIBUTES_EXCLUDE
*/
exclude: [
'request.headers.cookie',
'request.headers.authorization',
'request.headers.proxyAuthorization',
'request.headers.setCookie*',
'request.headers.x*',
'response.headers.cookie',
'response.headers.authorization',
'response.headers.proxyAuthorization',
'response.headers.setCookie*',
'response.headers.x*'
]
}
}
Loading