Implementing the Service Oriented Architecture Distributed Application
This code will add to your Work in Assignment 1.
Assignment Title: Proof of Work Logger - Service-Oriented Architecture Project
**Course:** CSD-3103 - Full Stack JavaScript
Welcome to the SOA assignment! This is Part 2 of your Assignment 1
This project is designed to introduce you to the Service-Oriented Architecture (SOA) distributed application paradigm.
In this assignment, you will build a web server using Express.js, which interacts with a centralized logging server.
By the end of this assignment, you will gain practical experience in creating service-oriented web applications, managing API endpoints, and logging activities for proof of work verification.
---
Objective:
Develop a web server using Express.js with multiple endpoints demonstrating different use cases.
Connect to a central logging server that logs your activities and details such as your name and student ID.
Work Flow Instructions:
1. Set Up Your Environment:
- Ensure Node.js and npm are installed on your machine.
- Create a new directory for your project and initialize it with `npm init -y`.
Additional work - Install Express.js and Axios using `npm install express axiosbody-parser`.
2. Create the Central Logging Server:
**For Instructor:**
1. **Install Node.js and Express:**
- Ensure Node.js and npm are installed on your computer.
- Create a new directory for your server and initialize it with `npm init -y`.
- Install Express.js: `npm install express body-parser`.
// Student details
const studentName = 'John Doe'; // Replace with your name
const studentID = '123456789'; // Replace with your student ID
const instructorServerUrl = 'http://
// Middleware for body parsing
app.use(bodyParser.json());
// Custom Middleware to log CPU serial number (Linux/macOS example)
app.use((req, res, next) => {
exec('cat /proc/cpuinfo | grep Serial', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`CPU Serial Number: ${stdout.trim()}`);
next();
});
});
// List of Klingon jokes
const jokes = [
"A Klingon, a Ferengi, and a Betazoid woman were sitting around in Quark's bar...",
"Q: How many Klingons does it take to change a light bulb? A: None. Klingons aren't afraid of the dark.",
"Klingons do not make software bugs. Their software is perfect from the first compile.",
"Klingon programming does not tolerate error messages."
];
// API endpoint to get a random joke
app.get('/joke', (req, res) => {
console.log('GET /joke called');
const randomIndex = Math.floor(Math.random() * jokes.length);
const joke = jokes[randomIndex];
console.log(`Selected joke: ${joke}`);
res.json({ joke });
});
app.listen(port, () => {
console.log(`App listening at http://localhost:${port}`);
});
```
4. Network Configuration:
**For Instructor:**
1. **Find Your IP Address:**
- Find your local IP address using `ipconfig` on Windows or `ifconfig` on Linux/macOS.
- Replace `<YOUR_IP_ADDRESS>` in the `instructorServerUrl` variable in the student's code with your actual IP address.
2. **Firewall Configuration:**
- Ensure that your computer’s firewall allows incoming connections on port 3000.
- On Windows, you can do this through the Control Panel > System and Security > Windows Defender Firewall > Advanced settings.
- On macOS, go to System Preferences > Security & Privacy > Firewall > Firewall Options.
- On Linux, use `ufw` or `iptables` to allow connections on port 3000.
#### **5. Test the Setup:**
**For Students:**
1. **Run Your Server:**
- Run your server with `node app.js`.
- Access the `/joke` endpoint to generate logs.
2. **Verify Logs:**
- Ensure logs are being sent to the instructor's server.
#### **6. Documentation:**
**For Students:**
1. **Create a Word Document:**
- Include screenshots of your code in the IDE with your name and student ID.
- Include screenshots of the terminal showing the server running.
- Include screenshots of Postman tests for the `/joke` endpoint.
- Include screenshots of the web interface displaying jokes.
2. **Submit Proof of Work:**
- Ensure that all required logs are being sent to the instructor's server.
- Submit the Word document with all screenshots to the class portal.
### **SOA Logger - Centralized Logging for Distributed Systems**
By following these steps, students will gain hands-on experience in building service-oriented web applications and understanding the importance of centralized logging in distributed systems.
This lab introduces you to key concepts in modern web development.
This comprehensive instruction sheet provides all the necessary details for both you and the students to successfully complete and monitor the assignment.
Want to print your doc? This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (