question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question on how to run standalone from command-line

See original GitHub issue

Hello again,

I have a question about how I could go about creating a mockttp standalone server through the command line that would always be listening.

What I am trying to accomplish is to have a server that is always running in one shell, that would pass through any requests that are not matching a rule. Then, I want to have tests that can configure the mock server to add/remove rules using code such that I can intercept and do the rewrites accordingly and reset to a default state when it finishes.

I read that I can do Running mockttp -c [test command], to start the server before your tests, and automatically shut it down afterwards. but I don’t want the server to shutdown.

Is this possible?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pimterrycommented, Jan 20, 2022

Yes, that looks like correct to me! Sounds like everything’s working for you now, so I’m going to close this, but feel free to reply here if you’re still having trouble, or open a new issue for anything else that comes up.

0reactions
sw-carlos-cristobalcommented, Jan 19, 2022

Excellent! I think this is what I was looking for!

I couldn’t get the event-based startup/shutdown to work because I was somehow getting into a loop of starting and stopping itself, but this worked well:

const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.get('/connect', (req, res) => {
  remoteServer.stop();
  res.send('Connection established');
});

app.get('/disconnect', (req, res) => {
  remoteServer.start(8000).then(() => {
    remoteServer.forUnmatchedRequest().thenPassThrough();
  });
  res.send('Connection disconnected');
});

app.listen(port, () => {
  console.log(`Listening at http://localhost:${port}`);
});

const standaloneServer = mockttp.getStandalone({
  debug: true,
  serverDefaults: {
    https: {
      keyPath: '../config/mockttp/ca.key',
      certPath: '../config/mockttp/ca.crt',
    },
  },
});
standaloneServer.start().then(() => {
  console.log('Standalone server started');
});

const remoteServer = mockttp.getRemote();
remoteServer.start(8000).then(() => {
  remoteServer.forUnmatchedRequest().thenPassThrough();
});

I would then make a GET request before and after tests to release the port I was using so I could connect with a remote server connection.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connect windows standalone aplication to command line
My question is how do i start my matlab function and connect it to the command line above? For example should i start...
Read more >
How can I pass command line arguments to a standalone ...
I need to find a way to make the varargin function without having MATLAB installed on the computer that's running the program. If...
Read more >
Description of the Windows Update Standalone Installer in ...
msu file is in the D:\934307 folder, type the following command at a command prompt to install the update package: wusa.exe d:\934307\Windows6.0-KB934307-x86.
Read more >
What is a command-line interface (CLI)? - TechTarget
A command-line interface (CLI) is a text-based user interface (UI) used to run programs, manage computer files and interact with the computer.
Read more >
Start standalone full-screen google chrome apps by command ...
I can run google-chrome app standalone this way: google-chrome --app="https://calendar.google.com/calendar/render#main_7".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found