parent
403bdaddbc
commit
3e14c20f75
6 changed files with 36 additions and 9 deletions
@ -0,0 +1,24 @@ |
||||
import { RequestHandler } from 'express'; |
||||
|
||||
import { configStriker } from './configStriker'; |
||||
import { sanitizeQS } from '../../sanitizeQS'; |
||||
import { stdout } from '../../shell'; |
||||
|
||||
// Ensure each create handler sends a response at the end of any branch.
|
||||
const MAP_TO_CREATE_HANDLER: Record<string, RequestHandler | undefined> = { |
||||
striker: configStriker, |
||||
}; |
||||
|
||||
export const createHost: RequestHandler = (...args) => { |
||||
const [ |
||||
{ |
||||
query: { hostType: rawHostType }, |
||||
}, |
||||
] = args; |
||||
|
||||
const hostType = sanitizeQS(rawHostType, { returnType: 'string' }); |
||||
|
||||
stdout(`hostType=[${hostType}]`); |
||||
|
||||
MAP_TO_CREATE_HANDLER[hostType]?.call(null, ...args); |
||||
}; |
@ -1,2 +1,3 @@ |
||||
export * from './createHost'; |
||||
export * from './getHost'; |
||||
export * from './getHostConnection'; |
||||
|
@ -1 +0,0 @@ |
||||
export { initializeStriker } from './command/initializeStriker'; |
@ -1,13 +1,9 @@ |
||||
import express from 'express'; |
||||
|
||||
import { initializeStriker } from '../lib/request_handlers'; |
||||
import { poweroffHost, rebootHost } from '../lib/request_handlers/command'; |
||||
|
||||
const router = express.Router(); |
||||
|
||||
router |
||||
.put('/initialize-striker', initializeStriker) |
||||
.put('/poweroff-host', poweroffHost) |
||||
.put('/reboot-host', rebootHost); |
||||
router.put('/poweroff-host', poweroffHost).put('/reboot-host', rebootHost); |
||||
|
||||
export default router; |
||||
|
@ -1,9 +1,16 @@ |
||||
import express from 'express'; |
||||
|
||||
import { getHost, getHostConnection } from '../lib/request_handlers/host'; |
||||
import { |
||||
createHost, |
||||
getHost, |
||||
getHostConnection, |
||||
} from '../lib/request_handlers/host'; |
||||
|
||||
const router = express.Router(); |
||||
|
||||
router.get('/', getHost).get('/connection', getHostConnection); |
||||
router |
||||
.get('/', getHost) |
||||
.get('/connection', getHostConnection) |
||||
.post('/', createHost); |
||||
|
||||
export default router; |
||||
|
Loading…
Reference in new issue