@@ -2,7 +2,7 @@ import 'dotenv/config';
22import express from 'express' ;
33import { fileURLToPath } from 'url' ;
44import { dirname , join } from 'path' ;
5- import { getContainers } from './services/docker.js' ;
5+ import { getContainers , restartContainer , stopContainer , startContainer } from './services/docker.js' ;
66import { checkWebsites } from './services/http.js' ;
77
88const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
@@ -34,6 +34,41 @@ app.get('/api/status', async (req, res) => {
3434 }
3535} ) ;
3636
37+ app . use ( express . json ( ) ) ;
38+
39+ app . post ( '/api/container/restart' , async ( req , res ) => {
40+ const { name } = req . body ;
41+ if ( ! name ) return res . status ( 400 ) . json ( { error : 'name requis' } ) ;
42+ try {
43+ await restartContainer ( name ) ;
44+ res . json ( { ok : true } ) ;
45+ } catch ( err ) {
46+ res . status ( 500 ) . json ( { error : err . message } ) ;
47+ }
48+ } ) ;
49+
50+ app . post ( '/api/container/stop' , async ( req , res ) => {
51+ const { name } = req . body ;
52+ if ( ! name ) return res . status ( 400 ) . json ( { error : 'name requis' } ) ;
53+ try {
54+ await stopContainer ( name ) ;
55+ res . json ( { ok : true } ) ;
56+ } catch ( err ) {
57+ res . status ( 500 ) . json ( { error : err . message } ) ;
58+ }
59+ } ) ;
60+
61+ app . post ( '/api/container/start' , async ( req , res ) => {
62+ const { name } = req . body ;
63+ if ( ! name ) return res . status ( 400 ) . json ( { error : 'name requis' } ) ;
64+ try {
65+ await startContainer ( name ) ;
66+ res . json ( { ok : true } ) ;
67+ } catch ( err ) {
68+ res . status ( 500 ) . json ( { error : err . message } ) ;
69+ }
70+ } ) ;
71+
3772export default app ;
3873
3974if ( process . argv [ 1 ] === fileURLToPath ( import . meta. url ) ) {
0 commit comments