Installing MirageJS

- Added axios configuration
- Added miragejs to mock api calls
This commit is contained in:
2020-11-09 20:55:10 +00:00
parent ed696b62a2
commit fe1a5d77c3
6 changed files with 246 additions and 0 deletions

16
plugins/axios.js Normal file
View File

@@ -0,0 +1,16 @@
export default function ({ $axios }, inject) {
// Create a custom axios instance
const api = $axios.create({
headers: {
common: {
Accept: 'text/plain, */*',
},
},
})
// Set baseURL to something different
api.setBaseURL(process.env.baseApiUrl)
// Inject to context as $api
inject('api', api)
}

23
plugins/mirage.js Normal file
View File

@@ -0,0 +1,23 @@
import { createServer } from 'miragejs'
if (process.env.NODE_ENV === 'development') {
startServer(0)
}
function startServer() {
createServer({
routes() {
this.namespace = 'api'
this.get('/movies', () => {
return {
movies: [
{ id: 1, name: 'Inception', year: 2010 },
{ id: 2, name: 'Interstellar', year: 2014 },
{ id: 3, name: 'Dunkirk', year: 2017 },
],
}
})
},
})
}