-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
92 lines (77 loc) · 3.23 KB
/
index.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
92
import express from 'express';
import fs from 'fs/promises';
const app = express();
const PORT = process.env.PORT || 3000;
const data = await fs.readFile('./goldenpaths.json', { encoding: 'utf8' });
const goldenPaths = JSON.parse(data);
app.use(express.json());
app.post('/getgoldenpaths', async (req, res) => {
console.log(`Received [${req.method}] to [${req.url}]`);
const platformType = req.body.PlatformType;
let result;
try {
// Filter golden paths based on platform type, if not return all paths
if (platformType === 'Container' || platformType === 'Serverless') {
result = goldenPaths.filter(path => path.PlatformType === platformType).map(path => ({
PathID: path.PathID,
PathName: path.PathName,
Platform: path.Platform,
PlatformType: path.PlatformType
}));
} else {
result = goldenPaths.map(path => ({
PathID: path.PathID,
PathName: path.PathName,
Platform: path.Platform,
PlatformType: path.PlatformType
}));
}
} catch (error) {
console.error('Error reading goldenpaths.json:', error);
res.status(500).send('Internal Server Error');
return;
}
res.json(result);
});
app.post('/getgoldenpath', async (req, res) => {
console.log(`Received [${req.method}] to [${req.url}]`);
const pathID = req.body.PathID;
let result;
try {
result = goldenPaths.filter(path => path.PathID === pathID).map(path => ({
PathID: path.PathID,
PathName: path.PathName,
Platform: path.Platform,
PlatformType: path.PlatformType,
PathDesciption: path.PathDesciption,
PathOwner: path.PathOwner,
CreatedDate: path.CreatedDate,
LastModifiedDate: path.LastModifiedDate,
PathStatus: path.PathStatus
}));
} catch (error) {
console.error('Error reading goldenpaths.json:', error);
res.status(500).send('Internal Server Error');
return;
}
res.json(result);
});
app.post('/getterraformstandards', async (req, res) => {
console.log(`Received [${req.method}] to [${req.url}]`);
res.send(`Our standards for terraform:
Location for resources should be in UK South
Tags should include an environment of "development" and a tag for the PathID that denotes the path in the form of P followed by an number e.g. P0005
names of items such as resource names varieables etc.. should be named with a prefix of the project code and a suffix of the resource name e.g. PR12578-rg`);
});
app.get('/callback', (req, res) => {
console.log(`Received [${req.method}] to [${req.url}]`);
res.send('You may close this tab and return to GitHub.com (where you should refresh the page ' +
'and start a fresh chat). If you are using VS Code or Visual Studio, return there.');
});
app.get('/', (req, res) => {
console.log(`Received [${req.method}] to [${req.url}]`);
res.send('This is a GitHub Copilot Extension, please use Copilot to interact with the agent.');
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});