lukeed / sirv

An optimized middleware & CLI application for serving static files~!
MIT License
1.07k stars 58 forks source link

Support for POST request #153

Closed loic-bellinger closed 1 year ago

loic-bellinger commented 1 year ago

Hello.

All apologies for asking (beginner here), but is that possible for sirv to handle POST requests? Or shall I go with Polka and not use sirv / sirv-cli at all?

My use case is testing a file upload feature on my local test server.

lukeed commented 1 year ago

sirv just serves files. there's no upload feature nor will there be. you will need to accept POST requests in your own server and process/save them accordingly. You can still use sirv within your Polka application to continue serving files though


polka()
  .get('/uploads/*', sirv('path/to', { ... }))
  .post('/uploads', async function (req,res) {
    try {
      var file = await parse(req)
    } catch (err) {
      res.statusCode = 400;
      console.error('upload.parse', err);
      return res.end('unable to parse file upload');
    }
    // ...
  })
  // ...
loic-bellinger commented 1 year ago

@lukeed Thanks a lot for your kind answer.

That is working well but I'm missing some useful sirv-cli feature (dynamic port allocation, printing colors to the shell). Do you think sirv-cli might be patched to expose the server it uses, so that this server could be passed to polka via the Server option?