-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #371 from Accenture/audit-fixes
Updated examples and fixed npm audit reports
- Loading branch information
Showing
11 changed files
with
2,784 additions
and
2,729 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4,782 changes: 2,483 additions & 2,299 deletions
4,782
examples/channels-example/frontend/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM node:10-alpine | ||
FROM node:14-alpine | ||
|
||
# Set working directory | ||
WORKDIR /opt/service/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
'use strict'; | ||
|
||
const Hapi = require('hapi'); | ||
const Hapi = require('@hapi/hapi'); | ||
const kafkaRoutes = require('./kafka/kafka-routes'); | ||
|
||
const port = 8000; | ||
const server = new Hapi.Server({ port }); | ||
const server = Hapi.server({ | ||
port, | ||
}); | ||
|
||
server.route(kafkaRoutes); | ||
|
||
const init = async () => { | ||
await server.start(); | ||
console.log(`Server running at: ${server.info.uri}`); | ||
await server.start(); | ||
console.log(`Server running at: ${server.info.uri}`); | ||
}; | ||
|
||
process.on('unhandledRejection', (err) => { | ||
console.log(err); | ||
process.exit(1); | ||
console.log(err); | ||
process.exit(1); | ||
}); | ||
|
||
init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,33 @@ | ||
'use strict'; | ||
|
||
const kafka = require('no-kafka'); | ||
const { Kafka } = require('kafkajs'); | ||
|
||
const KAFKA_HOSTS = process.env.KAFKA_HOSTS || 'localhost:9092'; | ||
const KAFKA_SOURCE_TOPICS = process.env.KAFKA_SOURCE_TOPICS || 'example'; | ||
|
||
const kafkaProducer = (message) => { | ||
const producer = new kafka.Producer({ | ||
connectionString: KAFKA_HOSTS, | ||
}); | ||
|
||
const stringMessageValue = JSON.stringify(message); | ||
|
||
return producer.init() | ||
.then(() => { | ||
const data = { | ||
topic: KAFKA_SOURCE_TOPICS, | ||
message: { | ||
value: stringMessageValue, | ||
}, | ||
}; | ||
|
||
return producer.send(data); | ||
}) | ||
.then((result) => { | ||
producer.end(); | ||
|
||
const { error } = result[0]; | ||
if (error) { | ||
return error; | ||
} | ||
|
||
console.log(`Message successfully produced to Kafka ${JSON.stringify(result)}`); | ||
return result; | ||
}) | ||
.catch((e) => { | ||
console.log(`Could not produce message to topic ${KAFKA_SOURCE_TOPICS}`); | ||
console.log(e); | ||
producer.end(); | ||
return e; | ||
}); | ||
}; | ||
const kafka = new Kafka({ | ||
clientId: 'channel-service', | ||
brokers: [KAFKA_HOSTS], | ||
}); | ||
const producer = kafka.producer(); | ||
|
||
exports.produce = { | ||
handler: (request) => { | ||
const msg = request.payload; | ||
|
||
return kafkaProducer(msg) | ||
.then(message => ({ status: 'ok', message })) | ||
.catch(message => ({ status: 'error', message })); | ||
}, | ||
handler: async (request) => { | ||
const msg = request.payload; | ||
|
||
try { | ||
await producer.connect(); | ||
await producer.send({ | ||
topic: KAFKA_SOURCE_TOPICS, | ||
messages: [{ value: JSON.stringify(msg) }], | ||
}); | ||
await producer.disconnect(); | ||
console.log('Message successfully produced to Kafka'); | ||
|
||
return { status: 'ok' }; | ||
} catch (error) { | ||
console.error('Failed to produce message to Kafka', error); | ||
return { status: 'error', message: error }; | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.