Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
service-mocker
Advanced tools
Service Mocker is an API mocking framework for frontend developers. With the power of service workers, we can easily set up mocking services without any real servers. It sets developers free from intricate workflows, complex documentations and endless proxies from server to server.
Q: Is Service Worker ready?
A: No, not yet.
Q: Is Service Mocker ready?
A: Yes! Welcome to the future!
Since you are likely to run Service Mocker only during development, you will need to add service-mocker
as a devDependency:
npm install service-mocker --save-dev
For legacy browsers, you may also need the polyfills:
npm install service-mocker-polyfills --save-dev
A typical mocker includes two parts: client
and server
. First, let's create a server script named server.js
:
// server.js
import { createServer } from 'service-mocker/server';
const { router } = createServer();
router.get('/greet', (req, res) => {
res.send('Hello new world!');
});
// or you can use the shorthand method
router.get('/greet', 'Hello new world!');
Then, we need to write a client script to connect to the server:
// app.js
import 'service-mocker-polyfills';
import { createClient } from 'service-mocker/client';
const client = createClient('path/to/server.js');
client.ready.then(async () => {
const response = await fetch('/greet');
console.log(await response.text());
});
After that, create a .html
file and include ONLY the client script:
<script src="app.js"></script>
Now navigate your browser to your local dev server (e.g. http://localhost:3000
). Open the console and you will see the following messages:
> [mocker:modern] connection established
>
> Hello new world!
Welcome to the future :clap:.
While using webpack, it's recommended to use sw-loader to create a standalone server script:
import scriptURL from 'sw-loader!path/to/server.js';
import { createClient } from 'service-mocker/client';
const client = createClient(scriptURL);
client.ready.then(...);
Dolphin Wood | Vincent Bel |
FAQs
The next generation front-end API mocking framework.
The npm package service-mocker receives a total of 102 weekly downloads. As such, service-mocker popularity was classified as not popular.
We found that service-mocker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.