enjoycoding / vite-plugin-mock-server

A mock server plugin for Vite.
MIT License
58 stars 13 forks source link

Not working in `preview` mode #26

Open Profesor08 opened 1 year ago

Profesor08 commented 1 year ago

If you start build preview vite preview of npm run preview, it not working, any api request returns index page.

Profesor08 commented 1 year ago

There are the docs https://vitejs.dev/guide/api-plugin.html#configurepreviewserver

import { Connect, Plugin, PreviewServerForHook, ViteDevServer } from "vite";

export const ViteMockServer = (options?: MockOptions): Plugin => {
  return {
    name: PLUGIN_NAME,
    configureServer: createConfiguratedServer(options),
    configurePreviewServer: createConfiguratedServer(options),
  };
};

const createConfiguratedServer = (options: MockOptions = {}) => {
  return async (server: ViteDevServer | PreviewServerForHook) => {
    // code
  };
};