Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions api-client/src/api/mockClient.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import * as dotenv from "dotenv"
import * as jsonServer from "json-server"
import data from "../mockData"
import routes from "../routes.json"

export function mockApp() {
dotenv.config()
const server = jsonServer.create()

server.use(jsonServer.rewriter({
'/api/v1/': '/$1',
'/api/v1/quiz/:slug': '/quiz?slug=:slug'
}))
const rules = {}
for (const key in routes) {
rules[`/api/${process.env.API_VERSION}${key}`] = routes[key]
}
server.use(jsonServer.rewriter(rules))
const router = jsonServer.router(data)
const middlewares = jsonServer.defaults()

Expand Down
1 change: 1 addition & 0 deletions api-client/src/routes.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"/": "/$1",
"/quiz/:slug": "/quiz?slug=:slug"
}
2 changes: 1 addition & 1 deletion api-client/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {mockApp} from "./api/mockClient";

// Start the JSONServer
export const app = mockApp()
export const app = mockApp()
1 change: 1 addition & 0 deletions api-client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"lib": ["es6"],
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
},
"include": [
"**.ts"
Expand Down