-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
30 lines (22 loc) · 987 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import path from 'path'
import express from 'express'
import cors from 'cors'
import mockApi from 'swagger-mock-api'
import { init as clientInit } from './client'
export { call, getClient } from './client'
export function init (defaultHost, getDefaultHeaders, options = {}) {
let mockServerPort
if (options.swagger) {
console.log('MOCK SERVER INIT')
mockServerPort = options.mockServerPort || 3000
const app = express()
// /node_modules/api-client/dist => 3 levels down to the project root
const swaggerFile = path.join(__dirname, '../../../', options.swagger)
app.use(cors(), mockApi({
swaggerFile,
watch: true // enable reloading the routes and schemas when the swagger file changes
}))
app.listen(mockServerPort, () => console.log(`Mock server listening on port ${mockServerPort}!`))
}
return clientInit(defaultHost, getDefaultHeaders, { ...options, mockServerPort })
}