funny curl

This commit is contained in:
2026-07-20 17:05:24 -05:00
parent 7369afb6bb
commit fbb9003ba9
3 changed files with 208 additions and 0 deletions
+24
View File
@@ -1,4 +1,25 @@
import { defineConfig } from 'astro/config';
import curlResponse from './src/curl-response.ts';
const curlPreview = {
name: 'curl-preview',
configureServer(server) {
server.middlewares.use(async (request, response, next) => {
const userAgent = request.headers['user-agent'] ?? '';
const path = request.url?.split('?', 1)[0];
if (request.method !== 'GET' || path !== '/' || !/^curl(?:\/|$)/i.test(userAgent)) {
next();
return;
}
const terminalResponse = curlResponse();
response.statusCode = terminalResponse.status;
terminalResponse.headers.forEach((value, name) => response.setHeader(name, value));
response.end(await terminalResponse.text());
});
},
};
export default defineConfig({
site: 'https://rummage.cc',
@@ -7,4 +28,7 @@ export default defineConfig({
port: 4321,
},
devToolbar: { enabled: false },
vite: {
plugins: [curlPreview],
},
});