Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const jsonServer = require('json-server'); // eslint-disable-line no-undef
const middlewares = jsonServer.defaults();
const server = jsonServer.create();
const protocol = 'http';
const host = 'localhost';
const port = 3000;
const endpoint = `${protocol}://${host}:${port}`;
const schema = {
'posts': [
{
'title': 'baz',
'author': 'foo',
'id': 1
},
{
'title': 'qux',
'author': 'bar',
'id': 1
}
var jsonServer = require('json-server')
var server = jsonServer.create() // Returns an Express server
var router = jsonServer.router(__dirname + '/db.json') // Returns an Express router
server.use(jsonServer.defaults) // logger, static and cors middlewares
server.use(router) // Mount router on '/'
module.exports = server;
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @flow
* @format
*/
const jsonServer = require('json-server');
const https = require('https');
const fs = require('fs');
const certFile = process.env.API_CERT_FILENAME ?? '.cache/mock_server.cert';
const keyFile =
process.env.API_PRIVATE_KEY_FILENAME ?? '.cache/mock_server.key';
const server = jsonServer.create();
const router = jsonServer.router('./mock/db.json');
const middlewares = jsonServer.defaults();
server.use(middlewares);
const buffer = fs.readFileSync('./mock/db.json', 'utf-8');
const db = JSON.parse(buffer);
// Add feg and feg_lte handlers
server.post('/magma/v1/feg', (req, res) => {
if (req.method === 'POST') {
res.status(200).jsonp('Success');
}
});
server.post('/magma/v1/feg_lte', (req, res) => {
if (req.method === 'POST') {
/**
* @author https://github.com/silence717
* @date on 2016/10/17
*/
var jsonServer = require('json-server');
var server = jsonServer.create();
var middlewares = jsonServer.defaults();
var bodyParser = require('body-parser');
var mockRouter = require('./mock/index');
// 添加默认的中间件 logger, static, cors and no-cache
server.use(middlewares);
// 解析 body
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({
extended: false
}));
server.use(mockRouter);
server.listen(4001, function() {
static create (port) {
const server = jsonServer.create();
const router = jsonServer.router(this.createDb());
server.use(jsonServer.defaults());
server.use(router);
const s = server.listen(port);
return s;
}
}
export default () => {
const server = jsonServer.create();
server.use(bodyParser.json());
const defaultRoute = server._router.stack.slice();
server.reset = () => {
server._router.stack = defaultRoute.slice();
};
server.listen(3000);
return server;
};
const jsonServer = require('json-server');
const ip = require('ip').address();
const server = jsonServer.create();
const middlewares = jsonServer.defaults();
const createDB = require('./db.js');
const mounted = require('./route');
const DB = createDB();
const router = jsonServer.router(DB);
server.use(jsonServer.bodyParser);
server.use(middlewares);
mounted(server, DB);
server.use(router);
server.listen(
{
host: ip,
port: 3167
if (req.url === '/last-availabilities-by-station'
|| (req.url.includes('/stations') && false === req.url.includes('/stations/'))
|| req.url.includes('/stations-step-1')) {
res.jsonp({
'hydra:member': res.locals.data,
'@context': 'local_bicing_http_call',
'@id': 'local_bicing_http_call_id',
'@type': 'local_bicing_http_call_type',
})
} else {
res.jsonp(res.locals.data)
}
}
const app = jsonServer.create();
let middlewaresOptions = {};
if (fs.existsSync()) {
middlewaresOptions.static = path.join(__dirname, './public')
}
const middlewares = jsonServer.defaults(middlewaresOptions);
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Methods', 'POST, GET, PUT, PATCH, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
});