It's possible to write handler files in a compile-to-js language by simply
writing the files in that language and registering a require hook when starting
mock-server
.
-
write a
.babelrc
in the mock-server root:// mock-server/.babelrc { "presets": ["@babel/preset-env"] }
Note: if you already have a
.babelrc
in your project's root, you can makemock-server
use that by simply not writing a.babelrc
in the mock-server root. -
write your handler files:
// mock-server/get.js export default function handler(req, res) { req.status(200).send("OK"); }
-
install
@babel/register
and start the server withmock-server --require @babel/register
-
write your handler files:
// mock-server/get.ts import { RequestHandler } from "express"; const handler: RequestHandler = (req, res) => { req.status(200).send("OK"); }; export default handler;
-
install
ts-node
and start the server withmock-server --require ts-node/register