APIGit
Native Git RepositoryVersioned, Git-native API repositoryAPI DesignOpenAPI, AsyncAPI and GraphQL editingAPI DocumentationPublish versioned docs from GitAPI GovernanceCheck OpenAPI and AsyncAPI standardsMock ServerFrom OpenAPI, GraphQL or Express.js codeTeam CollaborationOrganizations, teams, permissions and reviewsAI AgentsMCP server, llms.txt and Copy page for agentsCLILocal-first: lint, mock and publish from a terminal

The full API lifecycle

Design, document, mock and govern your APIs in one Git-native workspace, or local-first with the CLI and your coding agent.

Get started freeView pricing

Learning

Help DocsGetting StartedVideo TutorialsBlog

Support

Contact UsRequest a DemoReport an Issue
PricingAbout
Sign InSign Up for Free
APIGit

The Git-native, local-first API platform, ready for AI agents

Product

  • Native Git Repository
  • API Design
  • API Documentation
  • API Governance
  • Mock Server
  • Team Collaboration
  • AI Agents
  • CLI

Resources

  • Blog
  • Documentation
  • CLI Reference
  • MCP Server
  • Video Tutorials
  • Pricing
  • Contact

Company

  • About
  • Careers
  • Privacy Policy
  • Terms of Service
  • Service Level Agreement
  • Cookie Policy

© 2026 APIGit. All rights reserved.

Home / Blog / mock-server / mockserver-migration-guide

Mock Server Migration Guide

2024-11-09
APIGit Team
6 min read
mock-server

Updated November 2026: The old mock platform is gone. This guide now covers mock servers last published before November 9, 2024, which must be republished to work again. For everything else, see How code-based mocks work.

Introduction

On November 9, 2024, APIGIT launched a new MockServer backend, powered by Express.js and running in a Node.js sandbox environment. The old platform, at *.mock.apigit.com, has since been retired.

If your mock server was last published before that date, it is not reachable until you republish it. If you were sent here by a notice on your mock server's page, this guide is for you. Moving from the old version (pure JavaScript-based) to the new one involves some breaking changes.

What You Need to Do

  1. Check your plan. These are code-based mock servers, and republishing one needs a Team or Enterprise plan.
  2. Update your scripts in the apigit-mock/ folder, as described below. apigit-mock/main.js must exist.
  3. Open the mock server from the Publish Center and click Republish, which rebuilds it from the same commit and name. If you changed your scripts, overwrite the mock server from your new commit instead.
  4. Update your clients to the new URL.

On the Free plan? You can't republish a code-based mock server, but you can publish a new spec-based mock server from your OpenAPI document: it needs no scripts and works on every plan. To keep the responses your scripts returned, add them to the document as example values. See Migrating from a code-based mock.

Key Changes and Migration Details

1. URL Change for Mock Servers

Old URL format: your-mockserver.mock.apigit.com

New URL format: your-mockserver.mockserver.apigit.com

The old URL no longer answers. A republished mock server keeps its name, under the new host.

Example:

  • Old URL: https://your-mockserver.mock.apigit.com/endpoint
  • New URL: https://your-mockserver.mockserver.apigit.com/endpoint

Be sure to update any references in your client applications, documentation, and integrations.

2. Library Imports - No More Global Libraries Variables

In the old MockServer, several popular JavaScript libraries were globally available, allowing direct usage without explicit imports. These included:

  • lodash (_) (v4.17.21) - General utility functions
  • momentjs (moment) (v2.30.1) - Time and date handling
  • faker (faker) (v5.5.3) - Data generator
  • ajv (Ajv) (v6.10.0) - JSON schema validation
  • validator (validator) (v13.12.0) - Validation helper

In the new version of MockServer, these libraries must now be manually imported using require statements in your mock scripts before use. An import statement does not find them.

What You Need to Do:

  • Add appropriate require statements for any supported libraries used in your mock scripts.

Supported Libraries in the New MockServer

The new MockServer comes with popular JavaScript libraries pre-installed. It has no network access, so a library must be on this list or included in your apigit-mock/ folder. Below is a list of supported libraries and examples of how to use them:

  • @faker-js/faker (v9.2.0) - Data generator
  • ajv (v8.17.1) - JSON schema validation
  • base64-js (v1.5.1) - Base64 encoding/decoding
  • body-parser (v1.20.3) - Request body parsing
  • cookie-parser (v1.4.7) - Cookie parsing
  • cors (v2.8.5) - Cross-Origin Resource Sharing middleware
  • jsonwebtoken (v9.0.2) - JWT creation and verification
  • lodash (v4.17.21) - General utility
  • moment (v2.30.1) - Time and date handling
  • uuid (v11.0.3) - UUID generator
  • validator (v13.12.0) - Validation helper

Example Usage:

var moment = require('moment'); // require
const { faker } = require('@faker-js/faker');
const Ajv = require("ajv");
var validator = require('validator');
const base64 = require('base64-js');
const jwt = require('jsonwebtoken');
const { v4: uuidv4 } = require('uuid');
const _ = require('lodash');

function testLodash() {
  // Test data
  const users = [
    { id: 1, name: 'Alice', age: 25, active: true },
    { id: 2, name: 'Bob', age: 30, active: false },
    { id: 3, name: 'Charlie', age: 35, active: true },
    { id: 4, name: 'David', age: 40, active: false }
  ];

  // Example 1: Filter active users
  const activeUsers = _.filter(users, { active: true });
  console.log('Active Users:', activeUsers);

  // Example 2: Sort users by age in descending order
  const sortedByAge = _.orderBy(users, ['age'], ['desc']);
  console.log('Users sorted by age (desc):', sortedByAge);

  // Example 3: Get the names of all users
  const userNames = _.map(users, 'name');
  console.log('User Names:', userNames);
}

function testMoment() {
  console.log("Current time is:", moment().format());
}

function testUuidv4() {
  console.log("UUID is:", uuidv4());
}

function testAjv() {
  const ajv = new Ajv();
  const schema = {
    type: "object",
    properties: {
      foo: { type: "integer" },
      bar: { type: "string" },
    },
    required: ["foo"],
    additionalProperties: false,
  };
  const data = { foo: 1, bar: "abc" };
  const validate = ajv.compile(schema);
  const valid = validate(data);
  if (!valid) console.log(validate.errors);
}

function testBase64() {
  const text = 'Hello, world!';
  const textBytes = new TextEncoder().encode(text);
  const base64Encoded = base64.fromByteArray(textBytes);
  console.log('Base64 Encoded:', base64Encoded);

  const decodedBytes = base64.toByteArray(base64Encoded);
  const decodedText = new TextDecoder().decode(decodedBytes);
  console.log('Decoded Text:', decodedText);
}

function testValidator() {
  const result = validator.isEmail('fooo~bar.com');
  console.log("fooo~bar.com is email, right?", result);
}

function testFakerJS() {
  return {
    userId: faker.string.uuid(),
    username: faker.internet.username(),
    email: faker.internet.email(),
    avatar: faker.image.avatar(),
    password: faker.internet.password(),
    birthdate: faker.date.birthdate(),
    registeredAt: faker.date.past(),
  };
}

function testJwt() {
  const SECRET_KEY = 'your-secret-key';
  const payload = { userId: 123, username: 'testUser' };
  const token = jwt.sign(payload, SECRET_KEY, { expiresIn: '1h' });
  console.log('Generated Token:', token);
  try {
    const decoded = jwt.verify(token, SECRET_KEY);
    console.log('Decoded Payload:', decoded);
  } catch (err) {
    console.error('Token verification failed:', err.message);
  }
}

mock.get("/testlibs", function (req, res) {
  console.log("==== this is a test of libs supported =====");
  testLodash();
  testMoment();
  testUuidv4();
  testAjv();
  testValidator();
  testBase64();
  testJwt();
  const jsonData = testFakerJS();
  return res.status(200).json(jsonData);
});

3. Routes: mock.define() and mock.[get|post|delete|...]()

mock is now an express.js app, so you can define routes the native way with mock.[get|post|delete|...]().

mock.define(path, method, callback) still works, accepts {name} path parameters as well as :name, and is the way to have a route listed by GET /apigit-mockserver-routes.

What You Need to Do:

Nothing is required for existing mock.define() routes. See Routes and Middleware.

Back to Blog

Related Posts

Spec-Based Mock Servers: A Working Mock from Your OpenAPI Document

APIGit • 2026-11-06
mock-server

Publish a mock server from your OpenAPI documents without writing code. It validates requests, answers from your examples and schemas, and works on every plan.

Read More

Spec-Based or Code-Based: Which Mock Server Do You Need?

APIGit • 2026-11-06
mock-server

APIGit has two types of mock server. Here is how they differ, when each one fits, and how to run both from one repository.

Read More

Mock Servers That Tell You What Is Wrong

APIGit • 2026-11-06
mock-server

Spec-based mock servers validate each request against your OpenAPI document, return clear problem+json errors, and let clients pick a response with the Prefer header.

Read More

Ready to get started with APIGit?

Create a free workspace, add an OpenAPI file and publish your first API document and mock server in minutes.

Get Started Book a Demo