2021-12-28 17:49:11 +01:00
|
|
|
// src/server.js
|
2021-12-28 18:01:56 +01:00
|
|
|
import { createServer, Model } from 'miragejs'
|
2021-12-28 17:49:11 +01:00
|
|
|
|
2021-12-28 18:01:56 +01:00
|
|
|
export function makeServer ({ environment = 'development' } = {}) {
|
|
|
|
const server = createServer({
|
2021-12-28 17:49:11 +01:00
|
|
|
environment,
|
|
|
|
|
|
|
|
models: {
|
2021-12-28 18:01:56 +01:00
|
|
|
user: Model
|
2021-12-28 17:49:11 +01:00
|
|
|
},
|
|
|
|
|
2021-12-28 18:01:56 +01:00
|
|
|
seeds (server) {
|
|
|
|
server.create('user', { name: 'Bob' })
|
|
|
|
server.create('user', { name: 'Alice' })
|
2021-12-28 17:49:11 +01:00
|
|
|
},
|
|
|
|
|
2021-12-28 18:01:56 +01:00
|
|
|
routes () {
|
|
|
|
this.namespace = 'api'
|
2021-12-28 17:49:11 +01:00
|
|
|
|
2021-12-28 18:01:56 +01:00
|
|
|
this.get('/users', (schema) => {
|
2021-12-28 17:49:11 +01:00
|
|
|
return schema.users.all()
|
|
|
|
})
|
2021-12-28 18:01:56 +01:00
|
|
|
}
|
2021-12-28 17:49:11 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
return server
|
|
|
|
}
|