How to use @ng-apimock/core - 3 common examples

To help you get started, we’ve selected a few @ng-apimock/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rickvandermey / angular-starterkit / mockserver / mockserver.js View on Github external
return require(paths).handle(
					scenario,
					request,
					response,
					variables,
					req,
				);
			}
		}
	});

	next();
});

// Bind the mock middleware to the express server
app.use(apimock.middleware);

// Bind a route so you can modify the running mock server
app.use('/mocking', express.static(devInterface));

// Simple feedback the server is actually running
app.listen(app.get('port'), function() {
	console.log('app running on port', app.get('port'));
});
github rickvandermey / angular-starterkit / mockserver / mockserver.js View on Github external
'Access-Control-Allow-Headers',
		'Authorization, Content-Type, x-xsrf-token, Pragma, Cache-Control',
	);

	res.header(
		'Access-Control-Expose-Headers',
		'Authorization, Error-Data, x-xsrf-token',
	);

	res.header('Access-Control-Allow-Credentials', 'true');

	let mockCookie = cookie.parse(req.headers.cookie || '')['apimockid'];
	res.cookie('apimockid', mockCookie);

	// Retrieve a handler which handles state (can be pretty much any handler)
	let handler = ioc_container.default
		.get('Middleware')
		.getMatchingApplicableHandler(
			{
				method: 'PUT',
				url: '/ngapimock/variables',
			},
			{},
		);

	// Loop over the mocks of the handler and find the availability call
	handler.state._mocks.forEach(function(mock) {
		const strippedUrl = req.url.split('?')[0];

		const isSameStaticRequest =
			strippedUrl.startsWith(`/${mock.request.url}`) &&
			strippedUrl.endsWith('.json');
github rickvandermey / angular-starterkit / mockserver / mockserver.js View on Github external
const ioc_container = require('@ng-apimock/core/dist/ioc-container');

const helper = require('./helper');

const apimock = require('@ng-apimock/core');
const devInterface = require('@ng-apimock/dev-interface');

const app = express();

// Check parameter otherwise fall back to port 4000
app.set('port', process.env.PORT || 4000);

// Specify which mocks and presets to load
// - mocks should end with .mock.json
// - presets should end with .preset.json
apimock.processor.process({
	src: './mockserver',
});

// Add additional logging to the mockServer so we can debug if certain calls ever happened
// NOTE: Enable to allow additional logging
app.use(morgan('dev'));

// Add form data parser so we can check deprecated request bodies
app.use(bodyParser.urlencoded({ extended: true }));

// Add API wide headers which are dictated by nginx
app.use(function(req, res, next) {
	res.header('Access-Control-Allow-Origin', 'https://localhost:4202');

	res.header(
		'Access-Control-Allow-Methods',

@ng-apimock/core

ng-apimock core module

MIT
Latest version published 2 months ago

Package Health Score

76 / 100
Full package analysis