Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Developer Server Access Log Option #14853

Open
4 tasks done
cawoodm opened this issue Nov 2, 2023 · 3 comments
Open
4 tasks done

Developer Server Access Log Option #14853

cawoodm opened this issue Nov 2, 2023 · 3 comments

Comments

@cawoodm
Copy link

cawoodm commented Nov 2, 2023

Description

As a developer it can be very useful to see the "hits", access requests in the vite console.

Suggested solution

When running vite --access-logs vite should log each hit as is typical with web servers (like apache/nginx) or web frameworks (like flask):

image

Alternative

No response

Additional context

No response

Validations

@sapphi-red
Copy link
Member

You can do it like this.
https://x.com/kiliman/status/1719488313692766582

@virullius
Copy link

You can do it like this. https://x.com/kiliman/status/1719488313692766582

Bad link. Does any know what the workaround is and can post it here?

@YogSottot
Copy link

You can add in plugin

   {
      name: 'requestLogger',
      configureServer(server) {
        server.middlewares.use((req, res, next) => {
          console.log(`[${new Date().toISOString()}] ${req.method} ${req.url}`);
          next();
        });
      },
    },

Added requestLogger Plugin:
A custom plugin named requestLogger is added to the plugins array.
This plugin uses the configureServer method to add a middleware that logs the request method and URL.

Console Log for Requests:
Logs requests to the terminal in the format: "[timestamp] METHOD URL".

Result:
When you run the Vite dev server, it will now log all incoming HTTP requests to the console. This helps in debugging and monitoring access during development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants