Skip to content

Hoainam #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions bai2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const express = require('express')
const MathServiceClient = require('./goi2.js')
const app = express()
const port = 3000

app.use(express.json());

app.post('/api/register', async (req, res) => {
console.log(req.body);
const mathServiceClient = new MathServiceClient();
const result = await mathServiceClient.sum({
first_name: req.body.first_name,
last_name: req.body.last_name,
password: req.body.password,
password_confirmation: req.body.password_confirmation,
email: req.body.email
})
res.send({result});
})

app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
17 changes: 17 additions & 0 deletions goi2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const axios = require('axios');
function MathServiceClient() {
this.baseURL = process.env.MATH_SERVICE_URL || 'http://localhost:4000';
}

MathServiceClient.prototype.sum = async function (data) {
const config = {
url: `${this.baseURL}/api/users/register`,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
data
};
const response = await axios(config);
return response.data;
};

module.exports = MathServiceClient;
27 changes: 27 additions & 0 deletions kiemtra.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const express = require('express');
const validateUser = require('./testjoi.js');
const app = express();
const port = 4000;
app.use(express.json());
app.post('/api/users/register', (req, res) => {
console.log(req.body)
const { error } = validateUser(req.body);
if (error) {
res.json({ result: error.details[0].message})
return res.status(400).send(error.details[0].message);
}
// Nếu hợp lệ, tiếp tục xử lý
// const user = {
// first_name: req.body.first_name,
// last_name: req.body.last_name,
// password: req.body.password,
// email: req.body.email
// };
// res.send(user);
res.json({ result: "đăng ký thành công"})
});


app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});
12 changes: 0 additions & 12 deletions math.js

This file was deleted.

Loading