Skip to content

Commit

Permalink
followed the way of enabling mock on reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Pugma committed Dec 31, 2024
1 parent b8d8df6 commit 388e197
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
26 changes: 19 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ import { createApp } from 'vue'
import { createPinia } from 'pinia'
import router from './router'
import App from './App.vue'
import { initMock } from './mocks/handler'
import './index.scss'

await initMock()
const enableMocking = async () => {
if (!import.meta.env.DEV) {
return
}

const pinia = createPinia()
const app = createApp(App)
app.use(router)
app.use(pinia)
app.mount('#app')
const { worker } = await import('./mocks/handler')

// `worker.start()` returns a Promise that resolves
// once the Service Worker is up and ready to intercept requests.
return worker.start({ onUnhandledRequest: 'bypass' })
}

enableMocking().then(() => {
const pinia = createPinia()
const app = createApp(App)

app.use(router)
app.use(pinia)
app.mount('#app')
})
7 changes: 1 addition & 6 deletions src/mocks/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,4 @@ const handlers = [
...projectHandlers
]

export const initMock = async () => {
if (import.meta.env.DEV) {
const server = setupWorker(...handlers)
await server.start({ onUnhandledRequest: 'bypass' })
}
}
export const worker = setupWorker(...handlers)

0 comments on commit 388e197

Please sign in to comment.