Skip to content

Commit 085312a

Browse files
committed
refactor: regenerate services using CLI injection
1 parent 0014eaf commit 085312a

File tree

199 files changed

+3408
-625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+3408
-625
lines changed

microservices/cart-service/.dockerignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

microservices/cart-service/.env

Lines changed: 0 additions & 5 deletions
This file was deleted.

microservices/cart-service/.env.dev

Lines changed: 0 additions & 5 deletions
This file was deleted.

microservices/cart-service/ecosystem.config.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

microservices/cart-service/package.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

microservices/cart/.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
#These files wont be sent to the docker builder during the COPY . . command
3+
4+
node_modules
5+
bar
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
12
FROM node:18-alpine3.18
23

34
WORKDIR /app
45

5-
COPY package.json ./
6+
COPY package.json .
67

78
RUN yarn install
89

910
COPY . .
1011

11-
CMD [ "yarn", "dev" ]
12+
CMD [ "yarn","dev" ]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
module.exports = {
3+
apps : [{
4+
name : cart,
5+
autorestart: true,
6+
watch: true,
7+
time: true,
8+
script : "./index.js",
9+
instances:4,
10+
env_production: {
11+
NODE_ENV: "prod",
12+
DATABASE_URL="mongodb://mongodb:27017/microservices-suite_cart_proddb",
13+
EXCHANGE="@monorepo",
14+
AMQP_HOST="amqp://rabbitmq:5672",
15+
PORT:9010
16+
},
17+
env_development: {
18+
NODE_ENV: "dev",
19+
DATABASE_URL="mongodb://mongodb:27017/microservices-suite_cart_devdb",
20+
EXCHANGE="@monorepo",
21+
AMQP_HOST="amqp://rabbitmq:5672",
22+
PORT:9010
23+
}
24+
}]
25+
}
26+

microservices/cart/index.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
const http = require('http');
3+
const express = require('express');
4+
const mongoose = require('mongoose');
5+
const { config, morgan, logger } = require('@microservices-suite/config');
6+
const { errorHandler } = require('@microservices-suite/errors');
7+
const { validate, APIError } = require('@microservices-suite/utilities');
8+
const { getUsers } = require('./src/services');
9+
const { router } = require('./src/routes');
10+
const { subscriber } = require('./src/subscriber');
11+
const rabbitmq = require('@microservices-suite/broker/rabbitmq');
12+
// const app = require('./src/app');
13+
14+
mongoose.connect(config.db).then(() => {
15+
logger.info(`📀 successfully connected to db: ${config.db}`);
16+
}).catch(err => {
17+
logger.error(`failed to connect to db. Exiting... ${err.message}`);
18+
process.exit(0);
19+
});
20+
21+
const app = express();
22+
23+
app.use(express.json());
24+
25+
app.get('/', (req, res) => {
26+
res.json({ message: 'hello from @microservices-suite/cart' });
27+
});
28+
29+
const server = http.createServer(app);
30+
31+
server.on('error', (err) => {
32+
logger.error(err);
33+
if (err.code === 'EADDRINUSE') {
34+
logger.error('Address already in use, retrying...');
35+
setTimeout(() => {
36+
server.close();
37+
server.listen(config.port, 'localhost');
38+
}, 1000);
39+
errorHandler(err);
40+
}
41+
});
42+
43+
server.listen(config.port, async() => {
44+
logger.info(`🚀 @microservices-suite/cart listening at: http://localhost:${config.port}`);
45+
const channel = await rabbitmq.workerQueue.amqpInitializeQueue({ config });
46+
await rabbitmq.workerQueue.consumeFromQueue({
47+
channel,
48+
queue: 'cart',
49+
subscriberHandler: subscriber.subscriberHandler
50+
});
51+
});
52+
53+
app.use(morgan.errorHandler);
54+
55+
app.use(morgan.successHandler);
56+
57+
app.use('/api/v1', router);
58+
59+
// Global error handler should come after all other middlewares
60+
app.all('*', (req, res, next) => {
61+
const err = new APIError(404, `requested resource not found on server: ${req.originalUrl}`);
62+
next(err);
63+
});
64+
65+
app.use(errorHandler);

microservices/cart/package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "@microservices-suite/cart",
3+
"version": "1.0.0",
4+
"description": "This is the cart service. TODO: update this description",
5+
"main": "index.js",
6+
"author": "Gilbert",
7+
"license": "MIT",
8+
"dependencies": {
9+
"@microservices-suite/config": "1.0.0",
10+
"@microservices-suite/errors": "1.0.0",
11+
"@microservices-suite/utilities": "1.0.0",
12+
"@microservices-suite/broker": "1.0.0",
13+
"dotenv": "^16.4.5",
14+
"express": "^4.18.3",
15+
"helmet": "^7.1.0",
16+
"mongodb": "^6.5.0",
17+
"mongoose": "^8.2.1",
18+
"morgan": "^1.10.0",
19+
"pm2": "^5.3.1",
20+
"winston": "^3.12.0"
21+
},
22+
"devDependencies": {
23+
"nodemon": "^3.1.0"
24+
},
25+
"workspaces": {
26+
"nohoist": [
27+
"**/@microservices-suite/utilities/",
28+
"**/@microservices-suite/utilities/**",
29+
"**/@microservices-suite/errors/",
30+
"**/@microservices-suite/errors/**",
31+
"**/@microservices-suite/config/",
32+
"**/@microservices-suite/config/**",
33+
"**/@microservices-suite/broker/",
34+
"**/@microservices-suite/broker/**"
35+
]
36+
},
37+
"scripts": {
38+
"release": "npx bumpp-version@latest && npm publish",
39+
"dev": "NODE_ENV=dev nodemon --legacy-watch -q index.js",
40+
"start": "pm2-runtime start ecosystem.config.js --env production",
41+
"stoprod": "pm2 stop ecosystem.config.js",
42+
"deletprod": "pm2 delete ecosystem.config.js",
43+
"test": "jest"
44+
},
45+
"private": true
46+
}

0 commit comments

Comments
 (0)