johnpapa / johnpapa/lite-server

Add Simple Mock Rest Endpoint Feature

Open
#103 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.3k
Forks
262
PR merge metrics
No merged PRs in 30d

Description

Would be nice to be able to add simple static mock REST endpoints to the json (not .js) config to speed up development. I modified an example from the lite-serve readme & the link below to create such an endpoint in bs-config.js (not .json):

// complete bs-config.js
// from lite-server readme and
// https://scotch.io/bar-talk/a-fast-and-convenient-development-server-with-lite-server

function mockGetRestMiddleware(req, res, next) {
var parsed = require("url").parse(req.url);
if (parsed.pathname.match(/XXX\/api\/user/)) {
res.setHeader('Content-Type', 'application/json');
res.end('{"id":4, "username":"George"}');
}
next();
}

module.exports = function(bs) {
return { server: {middleware: {
2: mockGetRestMiddleware
}}};};

But what would be nicer would be to be able to add path/json pairs to the server section of bs-config.json something like:

"server" : {
"mockGetRestEndpoints" : {
"api/product/*" : { "id": 1, "name" : "hammer" },
"api/current_user" : {"id":97088, "name":"Bill"}
},
// as normal
}

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.