haixuxu / vite-plugin-mockit

vite-plugin-mockit
MIT License
5 stars 1 forks source link

res.status don't work #2

Open heruiwoniou opened 2 years ago

heruiwoniou commented 2 years ago

I want to response a 404 result, but res.status(404) don't work;


Update:

For now, I'm using the original method to this problem:

    res.writeHead(404, {
      'Content-Type': 'application/json'
    });
    res.end(
      JSON.stringify({
        status: 1401,
        error: 'Not Found'
      })
    );
haixuxu commented 2 years ago

The status code will be overwritten When you use res.send to return data. https://github.com/xuxihai123/vite-plugin-mockit/blob/62354174f1/middleware/response.js#L34

The code snippet you provided is a solution. You can also do the following:

res.status(404); // or   res.statusCode=404 
res.end('data string');