programmatically or CLI to stop webpack-dev-server - webpack-dev-server

How to stop webpack-dev-server programatically of a CLI command against the port ?
Ctrl-C etc are good for manually stopping the server. We are basically killing it.
Is there a API that the server exposes to issue a STOP command or something ?

Just came across this. Hopefully it's still relevant^^
According to documentation, the server can be opened and closed via node api as follows:
// create instance
const server = new WebpackDevServer(webpack(config), { });
// start
server.listen(8000, "localhost", err => {
console.log("server started")
})
// close/stop
server.close(() => {
console.log("server closed")
})
Docs: https://github.com/webpack/docs/wiki/webpack-dev-server

Related

Why is my .Net Core 3.1 API/SPA stopping suddenly when I use file-saver on the client app while running in Visual Studio/IIS?

I have an odd issue related to running a React front end with a .Net Core 3.1 Web API. I used the Visual Studio template to create the app, so the client app exists inside my .Net Core project and is launched when I launch the API.
I have an API endpoint that returns a text/csv file via a FileStreamResult, and then I am using the npm package file-saver to allow the client to save the file on the front end. The file is being returned and saved successfully, but every time I run the saveAs function from my client app, the API shuts down when running in IIS on Visual Studio It just stops. Nothing in the logs, though I have set them to verbose. It shows the API being hit and the response being returned, but nothing else. I've also searched the Event Logs, but can't find any errors at the times of the shutdowns. It happens consistently. If I dont' save the file, the API does not shut down, but as soon as I save the file, it does.
If I run the API from Powershell using 'dotnet run,' the file is returned and saved successfully and the API does not shut down. I feel like this might be an IIS configuration issue, but I'm not sure how to resolve it.
I'm running Visual Studio Community 2019 version 16.10.2 and .Net Framework version 4.8.04084
The code in my Startup.cs that runs the React app is
app.UseSpa(spa =>
{ spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseProxyToSpaDevelopmentServer("http://localhost:3000");
}
});
and my front-end code to retrieve and save the file looks like
try {
const response = await fetch(URL, options);
const file = await response.blob();
saveAs(file, fileName);
} catch (err) {
...
}
And my logs:
{"Timestamp":"2021-07-22T08:50:58.9565584-05:00","Level":"Information","MessageTemplate":"Executing endpoint '{EndpointName}'","RenderedMessage":"Executing endpoint '\"CommissionDatabase.WebApp.Controllers.ExportController.GetAICommissionExport (CommissionDatabase.WebApp)\"'","Properties":{"EndpointName":"CommissionDatabase.WebApp.Controllers.ExportController.GetAICommissionExport (CommissionDatabase.WebApp)","EventId":{"Name":"ExecutingEndpoint"},"SourceContext":"Microsoft.AspNetCore.Routing.EndpointMiddleware","RequestId":"8000008b-0004-fd00-b63f-84710c7967bb","RequestPath":"/api/exports/aicommissions","SpanId":"|db35c5e7-4e2963d2e6602a10.","TraceId":"db35c5e7-4e2963d2e6602a10","ParentId":"","Application":"ims-api"}}
{"Timestamp":"2021-07-22T08:50:58.9619447-05:00","Level":"Information","MessageTemplate":"Route matched with {RouteData}. Executing controller action with signature {MethodInfo} on controller {Controller} ({AssemblyName}).","RenderedMessage":"Route matched with \"{action = \\\"GetAICommissionExport\\\", controller = \\\"Export\\\"}\". Executing controller action with signature \"System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] GetAICommissionExport(CommissionDatabase.Domain.DTO.FileExportDTO)\" on controller \"CommissionDatabase.WebApp.Controllers.ExportController\" (\"CommissionDatabase.WebApp\").","Properties":{"RouteData":"{action = \"GetAICommissionExport\", controller = \"Export\"}","MethodInfo":"System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] GetAICommissionExport(CommissionDatabase.Domain.DTO.FileExportDTO)","Controller":"CommissionDatabase.WebApp.Controllers.ExportController","AssemblyName":"CommissionDatabase.WebApp","EventId":{"Id":3,"Name":"ControllerActionExecuting"},"SourceContext":"Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker","ActionId":"1197f939-11ae-4c34-bd03-922af3942f00","ActionName":"CommissionDatabase.WebApp.Controllers.ExportController.GetAICommissionExport (CommissionDatabase.WebApp)","RequestId":"8000008b-0004-fd00-b63f-84710c7967bb","RequestPath":"/api/exports/aicommissions","SpanId":"|db35c5e7-4e2963d2e6602a10.","TraceId":"db35c5e7-4e2963d2e6602a10","ParentId":"","Application":"ims-api"}}
{"Timestamp":"2021-07-22T08:50:59.0250952-05:00","Level":"Information","MessageTemplate":"{HostingRequestFinishedLog:l}","RenderedMessage":"Request finished in 2043.6825ms 304 ","Properties":{"ElapsedMilliseconds":2043.6825,"StatusCode":304,"ContentType":null,"HostingRequestFinishedLog":"Request finished in 2043.6825ms 304 ","EventId":{"Id":2},"SourceContext":"Microsoft.AspNetCore.Hosting.Diagnostics","RequestId":"800001f8-0002-fb00-b63f-84710c7967bb","RequestPath":"/favicon.ico","SpanId":"|db35c5e6-4e2963d2e6602a10.","TraceId":"db35c5e6-4e2963d2e6602a10","ParentId":"","Application":"ims-api"},"Renderings":{"HostingRequestFinishedLog":[{"Format":"l","Rendering":"Request finished in 2043.6825ms 304 "}]}}
{"Timestamp":"2021-07-22T08:50:59.7133458-05:00","Level":"Information","MessageTemplate":"Entity Framework Core {version} initialized '{contextType}' using provider '{provider}' with options: {options}","RenderedMessage":"Entity Framework Core \"3.1.16\" initialized '\"CommissionDatabaseContext\"' using provider '\"Microsoft.EntityFrameworkCore.SqlServer\"' with options: \"None\"","Properties":{"version":"3.1.16","contextType":"CommissionDatabaseContext","provider":"Microsoft.EntityFrameworkCore.SqlServer","options":"None","EventId":{"Id":10403,"Name":"Microsoft.EntityFrameworkCore.Infrastructure.ContextInitialized"},"SourceContext":"Microsoft.EntityFrameworkCore.Infrastructure","ActionId":"1197f939-11ae-4c34-bd03-922af3942f00","ActionName":"CommissionDatabase.WebApp.Controllers.ExportController.GetAICommissionExport (CommissionDatabase.WebApp)","RequestId":"8000008b-0004-fd00-b63f-84710c7967bb","RequestPath":"/api/exports/aicommissions","SpanId":"|db35c5e7-4e2963d2e6602a10.","TraceId":"db35c5e7-4e2963d2e6602a10","ParentId":"","Application":"ims-api"}}
{"Timestamp":"2021-07-22T08:50:59.9887399-05:00","Level":"Information","MessageTemplate":"Executed DbCommand ({elapsed}ms) [Parameters=[{parameters}], CommandType='{commandType}', CommandTimeout='{commandTimeout}']{newLine}{commandText}","RenderedMessage":"Executed DbCommand (\"23\"ms) [Parameters=[\"#__p_0='?' (DbType = Int32)\"], CommandType='Text', CommandTimeout='30']\"\r\n\"\"SELECT TOP(1) [c].[Id], [c].[Name]\r\nFROM [Carriers] AS [c]\r\nWHERE [c].[Id] = #__p_0\"","Properties":{"elapsed":"23","parameters":"#__p_0='?' (DbType = Int32)","commandType":"Text","commandTimeout":30,"newLine":"\r\n","commandText":"SELECT TOP(1) [c].[Id], [c].[Name]\r\nFROM [Carriers] AS [c]\r\nWHERE [c].[Id] = #__p_0","EventId":{"Id":20101,"Name":"Microsoft.EntityFrameworkCore.Database.Command.CommandExecuted"},"SourceContext":"Microsoft.EntityFrameworkCore.Database.Command","ActionId":"1197f939-11ae-4c34-bd03-922af3942f00","ActionName":"CommissionDatabase.WebApp.Controllers.ExportController.GetAICommissionExport (CommissionDatabase.WebApp)","RequestId":"8000008b-0004-fd00-b63f-84710c7967bb","RequestPath":"/api/exports/aicommissions","SpanId":"|db35c5e7-4e2963d2e6602a10.","TraceId":"db35c5e7-4e2963d2e6602a10","ParentId":"","Application":"ims-api"}}
{"Timestamp":"2021-07-22T08:51:00.0737948-05:00","Level":"Information","MessageTemplate":"Executing {FileResultType}, sending file with download name '{FileDownloadName}' ...","RenderedMessage":"Executing \"Microsoft.AspNetCore.Mvc.FileStreamResult\", sending file with download name '\"\"' ...","Properties":{"FileResultType":"Microsoft.AspNetCore.Mvc.FileStreamResult","FileDownloadName":"","EventId":{"Id":2,"Name":"ExecutingFileResultWithNoFileName"},"SourceContext":"Microsoft.AspNetCore.Mvc.Infrastructure.FileStreamResultExecutor","ActionId":"1197f939-11ae-4c34-bd03-922af3942f00","ActionName":"CommissionDatabase.WebApp.Controllers.ExportController.GetAICommissionExport (CommissionDatabase.WebApp)","RequestId":"8000008b-0004-fd00-b63f-84710c7967bb","RequestPath":"/api/exports/aicommissions","SpanId":"|db35c5e7-4e2963d2e6602a10.","TraceId":"db35c5e7-4e2963d2e6602a10","ParentId":"","Application":"ims-api"}}
{"Timestamp":"2021-07-22T08:51:00.0777075-05:00","Level":"Information","MessageTemplate":"Executed action {ActionName} in {ElapsedMilliseconds}ms","RenderedMessage":"Executed action \"CommissionDatabase.WebApp.Controllers.ExportController.GetAICommissionExport (CommissionDatabase.WebApp)\" in 1115.5799ms","Properties":{"ActionName":"CommissionDatabase.WebApp.Controllers.ExportController.GetAICommissionExport (CommissionDatabase.WebApp)","ElapsedMilliseconds":1115.5799,"EventId":{"Id":2,"Name":"ActionExecuted"},"SourceContext":"Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker","ActionId":"1197f939-11ae-4c34-bd03-922af3942f00","RequestId":"8000008b-0004-fd00-b63f-84710c7967bb","RequestPath":"/api/exports/aicommissions","SpanId":"|db35c5e7-4e2963d2e6602a10.","TraceId":"db35c5e7-4e2963d2e6602a10","ParentId":"","Application":"ims-api"}}
Thanks!

How to connect to Mosquitto by using react-websocket

After npm install react-websocket
I'm trying to connect Windows Mosquitto(MQTT Broker server).
and then I set the websocket address in my react source, but cannot receive messages from Mosquitto, and also cannot publish any messages to Mosquitto server.
But it works in glassfish server which is run by Java.
I think Mosquitto and glassfish server are same websocket server, but it seems to be that there is difference between them.
Is there solution to connect Mosquitto Broker server by using react-websocket library?
react-websocket library's version is 2.0.0
Mosquitto MQTT Broker server version is 1.5.4
import Websocket from 'react-websocket'
export default class WebsocketInput {
constructor(queue, onOpenCallback) {
this.queue = queue
this.websocket = new Websocket({
url: process.env.REACT_APP_WEBSOCKET_ADDRESS,
onMessage: function(data) {
queue.offer(JSON.parse(data))
},
onOpen: function() {
onOpenCallback()
}
})
this.websocket.setupWebsocket()
}
sendMessage(msg) {
this.websocket.state.ws.send(msg)
}
close() {
this.websocket.shouldReconnect = false
this.websocket.state.ws.close()
}
}
Here is React code and I downloaded this from https://github.com/door2door-io/simulation-demo. I set the url 'ws://localhost:9001', but can't receive any messages in React app.
port 1883
protocol mqtt
listener 9001
protocol websockets
And this is part of mosquitto.conf file. I run the server by typing mosquitto -v -c mosquitto.conf, and I run mosquitto server in Windows CMD.
thanks

Cypress error "The automation client disconnected. Cannot continue running tests." when running in Docker

I'm getting the following error when running a Cypress test suite in a Docker container:
The automation client disconnected. Cannot continue running tests.
Using this command, running in a cypress/browsers:node12.6.0-chrome75 container:
cypress run --browser=chrome
This seems to occur when running out of shm space.
By default, Docker creates a container with a /dev/shm shared memory space of 64MB.
This is typically too small for Chrome and could cause Chrome to crash.
I have found two options to resolve this:
Disable usage of /dev/shm:
// cypress/plugins/index.js
module.exports = (on, config) => {
// ref: https://docs.cypress.io/api/plugins/browser-launch-api.html#Usage
on('before:browser:launch', (browser = {}, args) => {
if (browser.name === 'chrome') {
args.push('--disable-dev-shm-usage')
return args
}
return args
})
}
Increase the size of /dev/shm in the container:
Run the container with docker run --shm-size=1gb (or whatever size you want)

Cannot launch flink from local host when trying to run it with webUI

I'm trying to debug my flink from intellij using the flink UI.
the problem it somethims doesn't launched throwing java.net.BindException: Could not start rest endpoint on any port in port range 8081
my piece of code that should let the flink ui run (from windows) is:
String osName = System.getProperty("os.name");
if (osName.toLowerCase().contains("win")) {
Configuration conf = new Configuration();
conf.setBoolean(ConfigConstants.LOCAL_START_WEBSERVER, true);
env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(conf);
} else {
env = StreamExecutionEnvironment.getExecutionEnvironment();
}
can you assist please?
If you cannot bind to a given network port that usually means it has been already taken. So check if there is any process running on that port (old job manager?) and kill it.
Alternatively, you can change the port with
conf.setInteger(RestOptions.PORT, 8082);
or if want to be on the save side specify a range
conf.setString(RestOptions.BIND_PORT, "8081-8099");
One can change the default port mapping in ../conf/flink-conf.yml file.
rest.port: 18081
or use port range e.g.
rest.bind-port: 18080-18090

How to run webstorm angularJS application standalone in chrome?

I have an angular application on my local machine, I can open my SPA from webstorm over chrome, firefox or IE, but if I try to open the same html file from my windows explorer without using the IDE, it only opens and runs in firefox but nothing on chrome and IE just a blank page. I remember reading that firefox has an internal server or some sort, and chrome doesn't, I don't remember where I read that, if any body knows why please help.
Long term, you are best off running a local fileserver IMO. You can check out python's simple server example http://effbot.org/librarybook/simplehttpserver.htm, or I typically run something like this in node:
var http = require('http');
var express = require('express');
var app = express();
app.use('./', express.static(__dirname + './'));
app.get('*', function(req, res) {
return res.redirect('./');
});
// Create a server
var server = app.listen(3513, function () {
console.log('Server listening on', 3512)
});
If it is pure angular you are using, you don't need a server, however you might be running into some security problems, try running without security and see what happens.
For OSX, open Terminal and run:
$ open -a Google\ Chrome --args --disable-web-security
For Linux run:
$ google-chrome --disable-web-security
Also if you're trying to access local files for dev purposes like AJAX or JSON, you can use this flag too.
-–allow-file-access-from-files
For Windows go into the command prompt and go into the folder where Chrome.exe is and type
chrome.exe --disable-web-security
That should disable the same origin policy and allow you to access local files.
Otherwise taking a look at the console is the most sane thing to do, sometimes error information will pop-up there.

Resources