initial commit of repl clone
parent
8aaf7bc78d
commit
53f67cd00a
@ -1,47 +1 @@
|
||||
# Astro Starter Kit: Minimal
|
||||
|
||||
```sh
|
||||
npm create astro@latest -- --template minimal
|
||||
```
|
||||
|
||||
[](https://stackblitz.com/github/withastro/astro/tree/latest/examples/minimal)
|
||||
[](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/minimal)
|
||||
[](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/minimal/devcontainer.json)
|
||||
|
||||
> 🧑🚀 **Seasoned astronaut?** Delete this file. Have fun!
|
||||
|
||||
## 🚀 Project Structure
|
||||
|
||||
Inside of your Astro project, you'll see the following folders and files:
|
||||
|
||||
```text
|
||||
/
|
||||
├── public/
|
||||
├── src/
|
||||
│ └── pages/
|
||||
│ └── index.astro
|
||||
└── package.json
|
||||
```
|
||||
|
||||
Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.
|
||||
|
||||
There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.
|
||||
|
||||
Any static assets, like images, can be placed in the `public/` directory.
|
||||
|
||||
## 🧞 Commands
|
||||
|
||||
All commands are run from the root of the project, from a terminal:
|
||||
|
||||
| Command | Action |
|
||||
| :------------------------ | :----------------------------------------------- |
|
||||
| `npm install` | Installs dependencies |
|
||||
| `npm run dev` | Starts local dev server at `localhost:4321` |
|
||||
| `npm run build` | Build your production site to `./dist/` |
|
||||
| `npm run preview` | Preview your build locally, before deploying |
|
||||
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
|
||||
| `npm run astro -- --help` | Get help using the Astro CLI |
|
||||
|
||||
## 👀 Want to learn more?
|
||||
|
||||
Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
|
||||
# ReplIt Clone
|
||||
@ -1,4 +1,26 @@
|
||||
import { defineConfig } from 'astro/config';
|
||||
import { defineConfig } from 'astro/config'
|
||||
|
||||
import preact from '@astrojs/preact'
|
||||
import node from '@astrojs/node'
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({});
|
||||
export default defineConfig({
|
||||
integrations: [preact()],
|
||||
output: 'server',
|
||||
|
||||
adapter: node({
|
||||
mode: 'standalone',
|
||||
}),
|
||||
|
||||
vite: {
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:5432',
|
||||
ws: true,
|
||||
rewriteWsOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,15 +1,28 @@
|
||||
{
|
||||
"name": "repl-clone",
|
||||
"type": "module",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"dev": "astro dev",
|
||||
"start": "astro dev",
|
||||
"build": "astro build",
|
||||
"preview": "astro preview",
|
||||
"astro": "astro"
|
||||
},
|
||||
"dependencies": {
|
||||
"astro": "^4.15.6"
|
||||
}
|
||||
}
|
||||
"name": "repl-clone",
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "run-p dev:*",
|
||||
"dev:astro": "astro dev",
|
||||
"dev:server": "node ./server/server.js",
|
||||
"build:astro": "astro build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/node": "^8.3.3",
|
||||
"@astrojs/preact": "^3.5.3",
|
||||
"@xterm/addon-fit": "^0.10.0",
|
||||
"@xterm/xterm": "^5.5.0",
|
||||
"astro": "^4.15.6",
|
||||
"express": "^4.21.0",
|
||||
"node-pty": "^1.0.0",
|
||||
"preact": "^10.24.0",
|
||||
"ws": "^8.18.0",
|
||||
"xterm-theme": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "^1.1.9",
|
||||
"@types/express": "^4.17.21",
|
||||
"npm-run-all": "^4.1.5"
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
import express from 'express'
|
||||
import { WebSocketServer } from 'ws'
|
||||
|
||||
import * as pty from 'node-pty'
|
||||
|
||||
const app = express()
|
||||
|
||||
app.use(express.json())
|
||||
|
||||
app.get('/api/foo', c => c.json({ foo: 42 }))
|
||||
|
||||
app.get('/api/docker/:tag', (req, res) => {
|
||||
wss.handleUpgrade(req, res.socket, req.headers, ws => {
|
||||
wss.emit('connection', ws, req)
|
||||
})
|
||||
})
|
||||
|
||||
const server = app.listen(5432, () => {
|
||||
console.log('Starting API server on :5432...')
|
||||
})
|
||||
|
||||
const wss = new WebSocketServer({ server })
|
||||
|
||||
wss.on('connection', (ws, req) => {
|
||||
const url = new URL(req.url, `http://${req.headers.host}`)
|
||||
const tag = url.pathname.split('/')[3]
|
||||
|
||||
console.log(`Client connected, initializing "${tag}"...`)
|
||||
|
||||
const docker = pty.spawn('docker', ['run', '--init', '-it', '--rm', tag, '/bin/sh'])
|
||||
|
||||
docker.onExit(e => {
|
||||
ws.send(JSON.stringify(e))
|
||||
ws.close()
|
||||
console.log('Client requested stop')
|
||||
})
|
||||
|
||||
docker.onData(data => {
|
||||
ws.send(data)
|
||||
})
|
||||
|
||||
ws.on('message', message => {
|
||||
docker.write(message)
|
||||
})
|
||||
|
||||
ws.on('close', () => {
|
||||
docker.kill()
|
||||
console.log('Client disconnected')
|
||||
})
|
||||
})
|
||||
@ -0,0 +1,40 @@
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
font: inherit;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
img {
|
||||
display: block;
|
||||
}
|
||||
|
||||
body {
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
/* Components */
|
||||
|
||||
.xterm {
|
||||
margin: 2rem;
|
||||
padding: 0.5rem;
|
||||
|
||||
border-radius: 0.5rem;
|
||||
overflow: clip;
|
||||
box-shadow: 0 0 2rem 0 #0003;
|
||||
|
||||
&.xterm-dom-renderer-owner-1 .xterm-rows {
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
import { Terminal } from '@xterm/xterm'
|
||||
import { FitAddon } from '@xterm/addon-fit'
|
||||
|
||||
import { Github } from 'xterm-theme'
|
||||
|
||||
const term = new Terminal({
|
||||
theme: Github,
|
||||
})
|
||||
|
||||
const fitAddon = new FitAddon()
|
||||
term.loadAddon(fitAddon)
|
||||
|
||||
console.log('Starting terminal...')
|
||||
term.loadAddon(fitAddon)
|
||||
term.open(document.getElementById('terminal'))
|
||||
|
||||
fitAddon.fit()
|
||||
|
||||
const socket = new WebSocket(`ws://${location.host}/api/docker/alpine:latest`)
|
||||
|
||||
term.onData(data => {
|
||||
socket.send(data)
|
||||
})
|
||||
|
||||
socket.addEventListener('message', event => {
|
||||
term.write(event.data)
|
||||
})
|
||||
|
||||
socket.addEventListener('open', () => {
|
||||
term.write('Connected to backend container\r\n')
|
||||
})
|
||||
|
||||
socket.addEventListener('close', () => {
|
||||
term.write('\r\nDisconnected from backend container')
|
||||
})
|
||||
@ -1,16 +1,23 @@
|
||||
---
|
||||
|
||||
import '@xterm/xterm/css/xterm.css'
|
||||
import '../client/style.css'
|
||||
---
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>Astro</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Astro</h1>
|
||||
</body>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
|
||||
<title>docker+xterm.js</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>docker+xterm.js</h1>
|
||||
<div id="terminal"></div>
|
||||
|
||||
<script>
|
||||
import '../client/term.js'
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
FROM node:latest
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
CMD [ "node" ]
|
||||
@ -1,3 +1,7 @@
|
||||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
}
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
}
|
||||
}
|
||||
Reference in New Issue