0.3.2 • Published 10 months ago

@requestly/mock-server v0.3.2

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

requestly-mock-server

This Repo contains the core express server @requestly/mock-server package which powers Requestly's Cloud Mock Server.

Development

Install Dependencies

npm i

Start Server

npm start:dev

Usage with firebase-functions

Install

npm i @requestly/mock-server

Setup

import * as functions from 'firebase-functions';
import { MockServer } from '@requestly/mock-server';
import firebaseConfig from '../firebaseConfig';

const startMockServer = () => {
  const expressApp = new MockServer(3000, firebaseConfig, '/api/mockv2').app;

  return functions.runWith({ minInstances: isProdEnv() ? 1 : 0 }).https.onRequest(expressApp);
};

export const handleMockRequest = startMockServer();
class FirebaseConfig implements IConfig {
    getMockSelectorMap = (kwargs?: any) => {
        /**
        * Fetch and return mockSelectorMap from firestore
        * {
        *      mockId: {
        *          route: "",
        *          method: "",
        *      }
        * }
        */
    };
    
    getMock = (id: string, kwargs?: any) => {
        /**
        * Fetch mock details from firestore
        */
    }

    storeLog? = (log: Log) => {
        /**
        * Store log in cloud storages
        */
    }
}

const firebaseConfig = new FirebaseConfig();
export default firebaseConfig;

Requestly Cloud Mock Server Architechture

image

STEPS 1. Request coming from GET https://username.requestly.dev/users 2. Firebase Function passes the request to @requestly/mock-server 3. @requestly/mock-server - MockSelector a. Fetches all the available mocks using IConfig.getMockSelectorMap() (Firestore in case of Requestly) b. Select mock if any endpoint+method matches the incoming request (GET /users) c. Fetch Mock using IConfig.getMock(mockId) and pass it to MockProcessor 4. @requestly/mock-server - MockProcessor a. Process Mock - Response Rendering b. Return Response

0.3.2

10 months ago

0.3.1

10 months ago

0.2.13

12 months ago

0.2.12

12 months ago

0.2.11

12 months ago

0.2.10

1 year ago

0.3.0

11 months ago

0.2.9

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.8

1 year ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

3 years ago