-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
91 lines (78 loc) · 2.66 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// server.js - Node.js server with AppDynamics integration
const express = require('express');
const bodyParser = require('body-parser');
const { v4: uuidv4 } = require('uuid');
// AppDynamics Configuration
const APPDYNAMICS_CONFIG = {
controllerHostName: 'controller-IP-hostname',
controllerPort: PORT-Number,
controllerSslEnabled: true,
accountName: 'customer1',
accountAccessKey: 'eeds1224-087-863f-fc6d72ab',
applicationName: 'NodeJS-Test-App',
tierName: 'WebTier',
nodeName: 'TestNode-' + Math.floor(Math.random() * 1000)
};
// Initialize AppDynamics (must be first)
require('appdynamics').profile(APPDYNAMICS_CONFIG);
const app = express();
const PORT = process.env.PORT || 3000;
// Middleware
app.use(bodyParser.json());
app.use(express.static('public'));
// In-memory database
const db = {
products: [
{ id: 1, name: 'Laptop', price: 999.99, category: 'Electronics', stock: 50 },
{ id: 2, name: 'Smartphone', price: 699.99, category: 'Electronics', stock: 100 },
{ id: 3, name: 'Headphones', price: 149.99, category: 'Audio', stock: 200 },
{ id: 4, name: 'Monitor', price: 299.99, category: 'Electronics', stock: 30 }
],
users: [
{ id: 1, name: 'John Doe', email: '[email protected]', type: 'regular' },
{ id: 2, name: 'Jane Smith', email: '[email protected]', type: 'regular' },
{ id: 3, name: 'Admin User', email: '[email protected]', type: 'admin' }
],
orders: []
};
// Analytics Endpoint
app.post('/api/analytics', (req, res) => {
const event = req.body;
console.log('[Analytics Event]', event);
// Here you would normally send to AppDynamics analytics
// For this test, we'll just log it
res.status(200).json({ status: 'received' });
});
// Product Endpoints
app.get('/api/products', (req, res) => {
res.json(db.products);
});
app.get('/api/products/:id', (req, res) => {
const product = db.products.find(p => p.id === parseInt(req.params.id));
if (product) {
res.json(product);
} else {
res.status(404).json({ error: 'Product not found' });
}
});
// User Endpoints
app.get('/api/users', (req, res) => {
res.json(db.users);
});
// Order Endpoints
app.post('/api/orders', (req, res) => {
const order = {
id: uuidv4(),
...req.body,
status: 'completed',
date: new Date()
};
db.orders.push(order);
res.status(201).json(order);
});
// Start server
app.listen(PORT, () => {
console.log(`AppDynamics Analytics Test Server running on port ${PORT}`);
console.log('AppDynamics Controller:', APPDYNAMICS_CONFIG.controllerHostName);
console.log('Application Name:', APPDYNAMICS_CONFIG.applicationName);
});