funny curl
This commit is contained in:
@@ -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],
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user