-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compose tunnel agent: add docker API
- passthrough API to docker on port 3001 - websocket impl for exec and logs
- Loading branch information
Roy Razon
committed
Jul 31, 2023
1 parent
6dd0502
commit 7fc723f
Showing
21 changed files
with
692 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM node:18-alpine as development | ||
WORKDIR /app | ||
CMD [ "yarn", "-s", "dev" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,32 @@ | ||
import http from 'node:http' | ||
import url from 'node:url' | ||
import { Logger } from '@preevy/common' | ||
import { SshState } from './ssh/index' | ||
import { SshState } from './ssh' | ||
import { NotFoundError, respondAccordingToAccept, respondJson, tryHandler } from './http' | ||
|
||
const respond = (res: http.ServerResponse, content: string, type = 'text/plain', status = 200) => { | ||
res.writeHead(status, { 'Content-Type': type }) | ||
res.end(content) | ||
} | ||
|
||
const respondJson = ( | ||
res: http.ServerResponse, | ||
content: unknown, | ||
status = 200, | ||
) => respond(res, JSON.stringify(content), 'application/json', status) | ||
|
||
const respondNotFound = (res: http.ServerResponse) => respond(res, 'Not found', 'text/plain', 404) | ||
|
||
const createApiServer = ({ | ||
log, currentSshState, | ||
}: { | ||
const createApiServer = ({ log, currentSshState }: { | ||
log: Logger | ||
currentSshState: ()=> Promise<SshState> | ||
}) => http.createServer(async (req, res) => { | ||
log.debug('web request URL: %j', req.url) | ||
}) => { | ||
const server = http.createServer(tryHandler({ log }, async (req, res) => { | ||
log.debug('api request: %s %s', req.method || '', req.url || '') | ||
|
||
const { pathname: path } = url.parse(req.url || '') | ||
|
||
if (!req.url) { | ||
respondNotFound(res) | ||
return | ||
} | ||
const [path] = req.url.split('?') | ||
if (path === '/tunnels') { | ||
respondJson(res, await currentSshState()) | ||
return | ||
} | ||
|
||
if (path === '/tunnels') { | ||
respondJson(res, await currentSshState()) | ||
return | ||
} | ||
if (path === '/healthz') { | ||
respondAccordingToAccept(req, res, 'OK') | ||
return | ||
} | ||
|
||
if (path === '/healthz') { | ||
respond(res, 'OK') | ||
return | ||
} | ||
throw new NotFoundError() | ||
})) | ||
|
||
respondNotFound(res) | ||
}) | ||
return server | ||
} | ||
|
||
export default createApiServer |
Oops, something went wrong.