I am using log4js for logging the information. Want to print system logs. So how to do it? - protractor

I want to print the systems logs as its get printed using java and log4j.
However, i am not getting the way to write the system logs in protractor using log4js.
log4js.configure({
appenders: [
{
type: "clustered",
appenders: [
{
type: "dateFile",
filename: "log/access.log",
pattern: "-yyyy-MM-dd",
category: "http"
},
{
type: "file",
filename: "log/app.log",
maxLogSize: 10485760,
numBackups: 3
},
{
type: "logLevelFilter",
level: "ERROR",
appender: {
type: "file",
filename: "log/errors.log"
}
}
]
}
]

Related

After each Package.json update app cannot load newly hashed index.js Vite PWA

I have just installed the vite-plugin-pwa and followed the documentation and have the following in my config
VitePWA( {
injectRegister: 'auto',
registerType: 'autoUpdate',
devOptions: {
enabled: true
},
strategies: 'generateSW',
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg,mp3}'],
sourcemap: true
},
includeAssets: ['favicon.ico', 'apple-touch-icon.png', 'masked-icon.svg'],
manifest: {
name: 'Litreach',
short_name: 'Cluiche Litrithe',
start_url: "/",
display: "standalone",
lang: "ga",
description: 'Cluiche litrithe ina mbíonn ar an imreoir 5 fhocal a litriú gach lá. Cluintear na focail a rá sna 3 canúintí agus bíonn 5 iarracht agat an focal a litriú i gceart.',
theme_color: '#ffffff',
icons: [
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
"purpose": "maskable"
},
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
"purpose": "any"
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png'
}
],
dir: "ltr",
orientation: "portrait",
display_override: [
"standalone"
],
categories: [
"education",
"games"
]
}
})
However each time I bump the the package.json version number, the next time I go to load the app the application falls over. When I inspect the Network key I can see that the app is trying to load index.js?oldHashNumber and the only way I can get the app to load is manually pressing the refresh button on the browser.
I believe there is some problem with the Service Worker or my PWA configuration.
Should I try to destroy the Service Worker and all their caches and start again?
If so how should I do this?

AWS Api Gateway VTL Merge Json Object

Trying to merge the principalId from Lambda Authorizer into the payload that will be sent to Event Bridge.
So far I've gotten close by transforming to map and re-creating the Json object. The problem is that this Json object is printed out as a key:value pair with no quotes, So there's an error thrown.
According to the docs, there's non $util.toJson($map) available, this seems to be only available for AppSync.
const eventsAPI = new RestApi(this, 'eventsAPI', apigwOps);
const LambdaAuth0Authorizer = new LambdaAuth0Authorizer(this, 'LambdaAuth0Authorizer', {
env: {
auth0Audience: '',
auth0Domain: '',
},
});
const eventTypeResource = eventsAPI.root.addResource('event');
const options: IntegrationOptions = {
credentialsRole: apigwRole,
passthroughBehavior: PassthroughBehavior.NEVER,
requestParameters: {
'integration.request.header.X-Amz-Target': "'AWSEvents.PutEvents'",
'integration.request.header.Content-Type': "'application/x-amz-json-1.1'",
},
requestTemplates: {
'application/json': `
#set ( $map = $util.parseJson($input.body) )
#set ( $j = {
"eventType": "$map['eventType']",
"action": "$map['action']",
"subject": "$map['subject']",
"eventTime": $map['eventTime'],
"actor": "$context.authorizer.principalId"
}
)
{"Entries":
[
{
"Source": "com.xyz",
"Detail": "$util.escapeJavascript($j)",
"Resources": [],
"DetailType": "event",
"EventBusName": "${eventBus.eventBusName}"
}
]
}
`,
},
integrationResponses: [
{
statusCode: '200',
responseTemplates: {
'application/json': '',
},
},
],
};
eventTypeResource.addMethod('POST', new Integration({
type: IntegrationType.AWS,
uri: `arn:aws:apigateway:${env.region}:events:path//`,
integrationHttpMethod: 'POST',
options: options,
}), {
authorizer: LambdaAuth0Authorizer.authorizer,
methodResponses: [{ statusCode: '200' }],
requestModels: { 'application/json': getEventModel(this, eventsAPI) },
requestValidator: new RequestValidator(this, 'eventValidator', {
restApi: eventsAPI,
validateRequestBody: true,
}),
});
This generates:
{"Entries":
[
{
"Source": "com.uproarapi",
"Detail": "{eventType=FOLLOW, action=CREATE, subject=USER_777POIUY, eventTime=51644444444, actor=}",
"Resources": [],
"DetailType": "UpRoarEvent",
"EventBusName": "UpRoarEventBus"
}
]
}
With an error:
{"Entries":[{"ErrorCode":"MalformedDetail","ErrorMessage":"Detail is malformed."}],"FailedEntryCount":1}

AWS SAM Lambda typescript project doesnt attach to debugger in VSCode

I have used AWS SAM to initialize a typescript lambda project which I am editing in VSCode on Windows 10. I have also setup debug points in the typescript code and this is my launch.json
{
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"invokeTarget": {
"target": "template",
"logicalId": "HelloWorldFunction",
"templatePath": "${workspaceFolder}/lambda-app/template.yaml"
},
"lambda": {
"runtime": "nodejs14.x"
},
"sam": {
"containerBuild": false,
"skipNewImageCheck": false
},
"api": {
"httpMethod": "get"
},
"name": "templatestyle"
},
{
"type": "aws-sam",
"request": "direct-invoke",
"invokeTarget": {
"target": "code",
"lambdaHandler": "app.lambdaHandler",
"projectRoot": "${workspaceFolder}/lambda-app/hello-world"
},
"lambda": {
"runtime": "nodejs14.x",
"payload": {
"json": {
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
}
},
"sam": {
"containerBuild": false,
"skipNewImageCheck": false
},
"api": {
"httpMethod": "get"
},
"name": "basic"
}
]
}
This is my tsconfig.json
{
"compilerOptions": {
"target": "es2020",
"strict": true,
"preserveConstEnums": true,
"noEmit": true,
"sourceMap": true,
"module":"es2015",
"moduleResolution":"node",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
},
"include": ["*"],
"exclude": ["node_modules", "**/*.test.ts"]
}
This is the code in app.ts
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
/**
*
* Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
* #param {Object} event - API Gateway Lambda Proxy Input Format
*
* Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
* #returns {Object} object - API Gateway Lambda Proxy Output Format
*
*/
export const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
let response: APIGatewayProxyResult;
try {
response = {
statusCode: 200,
body: JSON.stringify({
message: 'hello world',
}),
};
} catch (err) {
console.log(err);
response = {
statusCode: 500,
body: JSON.stringify({
message: 'some error happened',
}),
};
}
return response;
};
When I select either of the debug configurations above, the break point only attaches in a file that is not part of what I created. It stops without a breakpoint on the first line below, which is seems to be in the path \var\runtime\index.js
Where did this file come from? Docker perhaps?. Also, why is it stopping here in this file and not in the breakpoint I put on my app.ts?
This is the result I get in the debug console, and the breakpoints I have set are not hit. How do I fix this?
By default the debugger will break on the first line of code. There is a switch to disable this. I don't see the command you are using for local invoke. I was able to get it to break on my source code by using the following:
sam local invoke <function logical id> --event events/event.json -d <port>
Function logical id is the name of your function in template.yml and port is the debug port to use. I used 9999. The command I used was
sam local invoke HelloWorldFunction --event events/event.json -d 9999

Adding lambda integration to HttpApi routes with SAM

I am currently attempting to have a AWS::Serverless::HttpApi integrate with a group of AWS::Serverless::Function's. The goal is to define these resources within a SAM template, and define the actual API using a swagger file.
I have my SAM template defined as so:
Resources:
apiPing:
Type: AWS::Serverless::Function
Properties:
Description: 'Ping'
CodeUri: ../bin/cmd-api-ping.zip
Handler: cmd-api-ping
Runtime: go1.x
Role:
Fn::GetAtt: apiLambdaRole.Arn
Events:
PingEvent:
Type: HttpApi
Properties:
ApiId: !Ref api
Path: /ping
Method: post
api:
Type: AWS::Serverless::HttpApi
Properties:
StageName: prod
DefinitionBody:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: swagger.yaml
AccessLogSettings:
DestinationArn: !GetAtt accessLogs.Arn
Format: $context.requestId
And my swagger file:
openapi: 3.0.1
info:
title: 'API'
version: 2019-10-13
paths:
/ping:
post:
summary: 'invoke ping'
operationId: 'apiPing'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PingRequest'
required: true
responses:
'200':
description: 'Successful'
content:
application/json:
schema:
$ref: '#/components/schemas/PongResponse'
x-amazon-apigateway-integration:
httpMethod: "POST"
type: aws_proxy
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${apiPing.Arn}/invocations
responses:
default:
statusCode: "200"
contentHandling: "CONVERT_TO_TEXT"
passthroughBehavior: "when_no_match"
components:
schemas:
PingRequest:
description: 'a ping request'
type: object
properties:
ping:
description: 'some text'
type: string
PongResponse:
description: 'a pong response'
type: object
properties:
pong:
description: 'some text'
type: string
This template deploys without any errors, however there is no integration attached to the /ping POST route.
The transformed template in CloudFormation does show a loaded swagger file:
"api": {
"Type": "AWS::ApiGatewayV2::Api",
"Properties": {
"Body": {
"info": {
"version": 1570924800000,
"title": "API"
},
"paths": {
"/ping": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PingRequest"
}
}
},
"required": true
},
"x-amazon-apigateway-integration": {
"contentHandling": "CONVERT_TO_TEXT",
"responses": {
"default": {
"statusCode": "200"
}
},
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${apiPing.Arn}/invocations"
},
"httpMethod": "POST",
"passthroughBehavior": "when_no_match",
"type": "aws_proxy"
},
"summary": "invoke ping",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PongResponse"
}
}
},
"description": "Successful"
}
},
"operationId": "apiPing"
}
}
},
"openapi": "3.0.1",
"components": {
"schemas": {
"PingRequest": {
"type": "object",
"description": "a ping request",
"properties": {
"ping": {
"type": "string",
"description": "some text"
}
}
},
"PongResponse": {
"type": "object",
"description": "a pong response",
"properties": {
"pong": {
"type": "string",
"description": "some text"
}
}
}
}
},
"tags": [
{
"name": "httpapi:createdBy",
"x-amazon-apigateway-tag-value": "SAM"
}
]
}
}
}
I'm trying to understand what I may need to change or add to add the integration to the http api. I can't find any clear explanation in the aws documentation.
I have managed to resolve this. aws::serverless::httpapi creates a AWS::ApiGatewayV2::Api resource. This requires a different integration than the previous versioned ApiGateway.
x-amazon-apigateway-integration has a key defined, payloadFormatVersion. Despite documentation suggesting both 1.0 and 2.0 are supported, it seems 2.0 must be used. As such, my x-amazon-apigateway-integration has become the following (I did clean it up a bit):
x-amazon-apigateway-integration:
payloadFormatVersion: "2.0"
httpMethod: "POST"
type: "aws_proxy"
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${apiPing.Arn}/invocations
responses:
default:
statusCode: "200"
connectionType: "INTERNET"
And with this, integration is applied upon deployment.

Facebook Messenger Bot Generic Template redirects to 'Watch' section

Recently I have noticed that the facebook video links that I pass on a generic template aka "cards" are redirecting the users to "watch" section of facebook.
-I know for sure that this is not an issue with the code but it must be something on facebook end?!
Is anyone experiencing this ?
To satisfy the "need to see some code" requests:
I'm using BootBot and this is my specific implementation:
const showLatestVideos = (payload, chat) => {
chat.say({
cards: [
{ title: '😅😅', image_url: 'https://scontent.fprn1-1.fna.fbcdn.net/v/t15.13418-10/p370x247/52063931_808166469575942_2311605833122709504_n.jpg?_nc_cat=106&_nc_ht=scontent.fprn1-1.fna&oh=fa00211a8bdf83959a23bac5971a19f8&oe=5CEE1050', default_action: {
type: "web_url",
url: "https://web.facebook.com/SwedenViral/videos/795477234150322/",
webview_height_ratio: "tall"
},
buttons:[
{
type:"web_url",
url:"https://web.facebook.com/SwedenViral/videos/795477234150322/",
title:"Tagga någon",
webview_height_ratio: "tall"
}
]
},
{ title: '😂🤣', image_url: 'https://scontent.fprn1-1.fna.fbcdn.net/v/t15.13418-10/p370x247/52171349_1186996514800023_9059384507546730496_n.jpg?_nc_cat=1&_nc_ht=scontent.fprn1-1.fna&oh=b9ca303276cbbeb131d5c659b2812e54&oe=5CE89DDB', default_action: {
type: "web_url",
url: "https://web.facebook.com/SwedenViral/videos/241869170093762/",
webview_height_ratio: "tall"
},
buttons:[
{
type:"web_url",
url:"https://web.facebook.com/SwedenViral/videos/241869170093762/",
title:"Berätta",
webview_height_ratio: "tall"
}
]
},
{ title: 'The most interesting and satisfying video you\'ll ever watch...', image_url: 'https://scontent.fprx1-1.fna.fbcdn.net/v/t15.5256-10/48349980_984643338399874_7749589283798777856_n.jpg?_nc_cat=102&_nc_ht=scontent.fprx1-1.fna&oh=d4b8f45f9115d561f66e519ec3cad053&oe=5D1DA1BB', default_action: {
type: "web_url",
url: "https://web.facebook.com/SwedenViral/videos/1021393401391534/",
webview_height_ratio: "tall"
},
buttons:[
{
type:"web_url",
url:"https://web.facebook.com/SwedenViral/videos/1021393401391534/",
title:"Kommentar",
webview_height_ratio: "tall"
}
]
},
{ title: 'Hur jag lämnande jobbet idga...🤣😂', image_url: 'https://scontent.fprn1-1.fna.fbcdn.net/v/t15.13418-10/p235x350/52142869_152469279005397_1516129000290779136_n.jpg?_nc_cat=1&_nc_ht=scontent.fprn1-1.fna&oh=0aed9824d288ce94f4ed426421c2d910&oe=5D282FFA', default_action: {
type: "web_url",
url: "https://web.facebook.com/SwedenViral/videos/816827101985067/",
webview_height_ratio: "tall"
},
buttons:[
{
type:"web_url",
url:"https://web.facebook.com/SwedenViral/videos/816827101985067/",
title:"Tagga någon",
webview_height_ratio: "tall"
}
]
}
]
});
};
And this is how the above content/message is sent:
bot.hear(['latest', 'videos', 'rate', 'senaste', 'videon'], showLatestVideos);
Answering this question/issue...
It turned out to be a Facebook bug which is fixed now! Hooray