Comments (3)
I may be wrong but I do think this is supported by express? I do remember that it worked with a manually build version of Node.js but not with the latest release @wesleytodd
from express.
Yeah that is quite possible. I thought the version with this fixed was supposed to go out with the security patch but maybe I misunderstood and it was set to land later? Based on this yes I am thinking that is the case: nodejs/node#51562 (comment)
from express.
Edit: this will light up once it fully lights up in Node, see the Node repro at the bottom
Here's my test harness rn, I don't think we support this automatically
✨✨✨
const express = require('express');
const app = express();
const router = express.Router();
app.use(express.json());
// Test using app.query (if this is valid)
try {
app.query('/test-app-query', (req, res) => {
console.log({ body: req.body });
res.status(200).json({ data: req.body });
});
console.log("app.query() tested and set up.");
} catch (error) {
console.error("app.query() failed:", error);
}
// Test using router.query (if this is valid)
try {
router.query('/test-router-query', (req, res) => {
console.log({ body: req.body });
res.status(200).json({ data: req.body });
});
app.use(router);
console.log("router.query() tested and set up.");
} catch (error) {
console.error("router.query() failed:", error);
}
// Fallback general middleware to check if QUERY method is getting through
app.use('/test', (req, res, next) => {
if (req.method === 'QUERY') {
console.log('Received QUERY method via general handler');
res.status(200).json({ received: req.body });
} else {
next();
}
});
// General error handler
app.use((err, req, res, next) => {
console.error('Error Handler:', { err });
res.status(500).send('Server Error');
});
app.listen(3000, () => {
console.log("Server listening on port 3000");
});
These are the curl requests Im using:
curl -i -X QUERY -H "Content-Type: application/json" -d '{"foo": "bar"}' http://localhost:3000/test-app-query
curl -i -X QUERY -H "Content-Type: application/json" -d '{"foo": "bar"}' http://localhost:3000/test-router-query
curl -i -X QUERY -H "Content-Type: application/json" -d '{"foo": "bar"}' http://localhost:3000/test
They each give me a response of:
HTTP/1.1 404 Not Found
X-Powered-By: Express
Content-Security-Policy: default-src 'none'
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Content-Length: 159
Date: Sat, 20 Apr 2024 22:33:30 GMT
Connection: keep-alive
Keep-Alive: timeout=5
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot undefined /test-app-query</pre>
</body>
</html>
CURL shouldn't matter here, but just in case:
curl --version
curl 8.4.0 (x86_64-apple-darwin23.0) libcurl/8.4.0 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.12 nghttp2/1.58.0
Release-Date: 2023-10-11
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL threadsafe UnixSockets
Maybe node really doesn't support this yet? Check this out:
const http = require('http');
// Do we know about query?
console.log(http.METHODS.includes('QUERY')) // true
// Create an HTTP server
const server = http.createServer((req, res) => {
// Log the method to the console for verification
console.log('Received method:', req.method);
// Check if the method is QUERY
if (req.method === 'QUERY') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Received a QUERY method request');
} else {
// Respond with Method Not Allowed if the method is not QUERY
res.writeHead(405, { 'Content-Type': 'text/plain' });
res.end('Method Not Allowed');
}
});
// Listen on port 3000
server.listen(3000, () => {
console.log('Server listening on port 3000');
});
node -v
# v21.7.3
curl -i -X QUERY -H "Content-Type: application/json" -d '{"foo": "bar"}' http://localhost:3000
HTTP/1.1 405 Method Not Allowed
Content-Type: text/plain
Date: Sat, 20 Apr 2024 23:22:16 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Transfer-Encoding: chunked
Method Not Allowed
from express.
Related Issues (20)
- Working On Vite+React. Have an Issue. HOT 1
- 4.19.0 breaks passing new URL() into res.redirect(...) HOT 7
- The npm latest version of express is 5.0.0-beta.2 !!! HOT 10
- Troubleshooting Node.js Express Server Routing Issue HOT 1
- mime.charsets in Response.js is undefined HOT 8
- WebAssembly Out of memory Error for any server HOT 2
- return res.redirect('back'); returns to '/' instead of the previous page HOT 2
- Need a clarification on router.param() usage. HOT 5
- [Question] Should Express.js v5.x drop support to older versions of Node? HOT 3
- .get() attempting to grab from home dir (Linux) HOT 2
- Request triager role for Ivaylo-Iv HOT 1
- Request triager role for etroynov HOT 2
- clean code for switch condition HOT 2
- Response location broken for unicode domains in latest release HOT 1
- help typing Request query with object
- Using colon as a character instead of path parameter (express 5) HOT 1
- Nominating @carpasse to the triage team HOT 7
- [v5] Lock down valid status code ranges to 1xx through 5xx HOT 10
- Can not set response headers when send a json body in a options request HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express.