基于 curl 的 REPL


\REPL over curl

这是一个关于如何在 curl() 上运行 REPL 实例的示例。

\This is an example on how to run a REPL instance over curl()

以下脚本在端口 8000 上启动一个 HTTP 服务器,该服务器可以接受通过 curl() 建立的连接。

\The following script starts an HTTP server on port 8000 that can accept a connection established via curl().

import http from 'node:http';
import repl from 'node:repl';
const server = http.createServer((req, res) => {
 res.setHeader('content-type', 'multipart/octet-stream');
 repl.start({
 prompt: 'curl repl> ',
 input: req,
 output: res,
 terminal: false,
 useColors: true,
 useGlobal: false,
 });
});
server.listen(8000);const http = require('node:http');
const repl = require('node:repl');
const server = http.createServer((req, res) => {
 res.setHeader('content-type', 'multipart/octet-stream');
 repl.start({
 prompt: 'curl repl> ',
 input: req,
 output: res,
 terminal: false,
 useColors: true,
 useGlobal: false,
 });
});
server.listen(8000);

运行上述脚本后,你可以使用 curl() 连接到服务器,并通过运行 curl --no-progress-meter -sSNT. localhost:8000 连接到其 REPL 实例。

\When the above script is running you can then use curl() to connect to the server and connect to its REPL instance by running curl --no-progress-meter -sSNT. localhost:8000.

警告:此示例仅用于教育目的,旨在演示如何使用不同的 I/O 流启动 Node.js REPL。它不应在生产环境或任何需要安全性的环境中使用,除非采取额外的保护措施。如果你需要在实际应用中实现 REPL,请考虑减轻这些风险的替代方法,例如使用安全输入机制和避免开放网络接口。

\Warning This example is intended purely for educational purposes to demonstrate how Node.js REPLs can be started using different I/O streams. It should not be used in production environments or any context where security is a concern without additional protective measures. If you need to implement REPLs in a real-world application, consider alternative approaches that mitigate these risks, such as using secure input mechanisms and avoiding open network interfaces.

来自 https://gist.github.com/TooTallNate/2053342 的原始代码。

\Original code from https://gist.github.com/TooTallNate/2053342.

AltStyle によって変換されたページ (->オリジナル) /