-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
77 lines (70 loc) · 1.99 KB
/
index.js
File metadata and controls
77 lines (70 loc) · 1.99 KB
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
const fastify = require('fastify')({ logger: true })
const dockerService = require('./DockerService.js')
//var dock = new Docker({socketPath: '/var/run/docker.sock'});
fastify.route({
method: 'GET',
url: '/',
schema: {
// request needs to have a querystring with a `name` parameter
querystring: {
name: { type: 'string' }
},
// the response needs to be an object with an `hello` property of type 'string'
response: {
200: {
type: 'object',
properties: {
hello: { type: 'string' }
}
}
}
},
// this function is executed for every request before the handler is executed
handler: async (request, reply) => {
this.dockerServiceInst = new dockerService();
//this.dockerServiceInst.pullDockerImage('rubinlab/mysql', 'latest');
this.dockerServiceInst.runContainer('rubinlab/mysql','latest', null , null);
/*dock.run('ubuntu', ['bash', '-c', 'uname -a'], process.stdout, function (err, data, container) {
console.log(err);
console.log(data);
console.log(container);
});*/
return { hello: this.dockerServiceInst.listContainers() }
}
})
fastify.route({
method: 'GET',
url: '/a',
schema: {
// request needs to have a querystring with a `name` parameter
querystring: {
cont: { type: 'string' }
},
// the response needs to be an object with an `hello` property of type 'string'
response: {
200: {
type: 'object',
properties: {
containerList: { type: 'string' }
}
}
}
},
// this function is executed for every request before the handler is executed
beforeHandler: async (request, reply) => {
// E.g. check authentication
},
handler: async (request, reply) => {
return { containerList: 'container 1' }
}
})
const start = async () => {
try {
await fastify.listen(3000)
fastify.log.info(`server listening on ${fastify.server.address().port}`)
} catch (err) {
fastify.log.error(err)
process.exit(1)
}
}
start()