Issue with Docker compose and Kestrel in asp.net 6.0 app - docker

I'm trying to run my aspnet 6.0 app using docker(Linux Container on Windows system) and having issues. it runs perfectly fine when I'm not trying to configure kestrel. But whenever i'm trying to add below code, i'm getting issue saying "This site can’t be reached localhost unexpectedly closed the connection."
builder.WebHost.ConfigureKestrel(serverOptions =>
{
serverOptions.Listen(IPAddress.Any, 5005, options =>
{
options.Protocols = HttpProtocols.Http2;
});
serverOptions.Listen(IPAddress.Any, 7173, options =>
{
options.Protocols = HttpProtocols.Http1AndHttp2;
});
});
I'm trying to use port 5005 for GRpc purpose and 7173 to expose rest api endpoints. I'm using visual studio 2022 and generated DockerFile by adding docker support.
Here are the docker compose,compose-override yaml and container snaps.
I have also tried adding https support, but no luck.
serverOptions.Listen(IPAddress.Any, 7173, options =>
{
options.Protocols = HttpProtocols.Http1AndHttp2;
options.UseHttps("appname.pfx", "password");
});
Please Note: all of the above lines of code works great when I'm not running on docker.

I think you can configure this in appsettings.json too:
{
"Logging": {
"LogLevel": {
"Default": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"WebApi": {
"Url": "http://localhost:7173",
"Protocols": "Http1"
},
"gRPC": {
"Url": "http://localhost:5005",
"Protocols": "Http2"
}
}
}
}

Had to expose same ports in DockerFile as pointed out in comment by #CodingMytra

Related

Nuxt Proxy Issue when deploying using Docker (Github Action)

I am trying to deploy my nuxt app using github actions. I tried to run my app built in docker container at my local environment, but it doesn't work. When I open application using browser,I could check nothing but the background image I set using css.
I believe it might be issue related to proxy or serverMiddleware that I set in nuxt.config.js.
Servermiddleware is for managing session, and proxy server is used to avoid CORS issues when getting data from external api server.
nuxt.config.js
proxy: {
'/api/v1/': {
target: 'http://192.168.219.101:8082',
pathRewrite: {'^/api/v1/cryptolive/': '/'},
changeOrigin: true,
},
}
serverMiddleware: [
// bodyParser.json(),
session({
secret: 'super-secret-key',
resave: false,
saveUninitialized: false,
cookie: {
maxAge: 60000,
},
}),
'~/apis',
],

ASP.NET Core 3.1 app on IIS Express: "This site can't be reached"

I'm working on an ASP.NET Core application that I have upgraded from v2.2 to v3.1.
When I start the application using IIS Express without SSL enabled, I get this error in Google Chrome:
This site can't be reached. localhost refused to connect.
When I enable SSL, I get this error instead:
This localhost page can't be found. No web page was found for the web address: https://localhost:44367.
I have have an IIS website configured to the directory where my application sits. In the project settings, I can set the 'Launch' setting to 'IIS', but when I do this I also get the same error.
Screenshot of my web project settings: .
When I create a new blank ASP.NET Core 3.1 web project and run it with the same settings on IIS Express, it runs fine.
Based on suggestions elsewhere, I have tried the following:
Cleaning and rebuilding
Deleting the .vs folder in the web project
Changing the port number (currently it is localhost:54236).
Enabling/disabling SSL
Restarting my machine
Loading up a fresh copy of my solution from Git on a separate working directory and trying to run it.
I'm at a loss.
Here is my launchSettings.json file:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iis": {
"applicationUrl": "http://myapplication.debug",
"sslPort": 0
},
"iisExpress": {
"applicationUrl": "http://localhost:54236",
"sslPort": 44367
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Web": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
When comparing with the launchSettings.json file of a fresh project I can't see any notable difference. Is there anything else that would cause this failure?
I should note that I did change the port number - it was initially at port number 50192, but when I attempt to run the website to that address (http://localhost:50192) it gives me a different error:
It appears I was missing something in my Program.cs when upgrading from aspnetcore 2.2 to 3.1.
Until now I had this:
return WebHost.CreateDefaultBuilder(args)
.ConfigureServices(services => services.AddAutofac())
.UseStartup<Startup>();
On looking at a fresh v3.1 project, it had something like this instead:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});

Swashbuckler/Swagger ignores Scheme setting

I'm using Swashbuckler ver. 5.6.0 in webapi project
configuration says:
c.Schemes(new[] { "https" });
Despite of this, when I access the swagger documentation page for my site,
it tries to load:
http://{swagger-docs-url}/swagger/v1, instead of https, and fails because of mixed content
What am I doing wrong here?
Can th
The c.Schemes(new[] { "https" }); in the configuration only impacts the generated swagger:
That will force the following output:
{
"swagger": "2.0",
"info": {
"version": "V1",
"title": "Swagger_Test",
},
"host": "yourhost.azurewebsites.net",
"schemes": [
"https"
],
Your question is not complete but I believe that what you are looking for is the rootUrl: https://github.com/domaindrivendev/Swashbuckle#rooturl
Actually, Swashbuckle will detect Uri on host and use the Uri Scheme / port as your {swagger-docs-url} , so if your host running on HTTP it only got HTTP, you can custom the rooturl to fix it.
//SwaggerConfig.cs
config.EnableSwagger(c =>
{
c.RootUrl(ResolveBasePath);
c.Schemes(new[] { "http", "https" });
}
internal static string ResolveBasePath(HttpRequestMessage message)
{
//fix for Cloudflare Flexible SSL and localhost test
var scheme = message.RequestUri.Host.IndexOf("localhost") > -1 ? "http://" : "https://";
return scheme + message.RequestUri.Authority;
}
I have a site using Cloudflare Flexible SSL, server running on HTTP but inbound connection to Cloudflare was HTTPS, so I need to force the Uri scheme as HTTPS, unless I test on my localhost.

Using environment variables in Ghost v1 config

In Ghost 0.x, config was provided via a single config.js file with keys for each env.
In Ghost 1.0, config is provided via multiple config.json files
How do you provide environment variables in Ghost 1.0?
I would like to dynamically set the port value using process.env.port on Cloud9 IDE like so.
config.development.json
{
"url": "http://localhost",
"server": {
"port": process.env.port,
"host": process.env.IP
}
}
When I run the application using ghost start with the following config, it says You can access your publication at http://localhost:2368, but when I go to http://localhost:2368 in http://c9.io it gives me an error saying No application seems to be running here!
{
"url": "http://localhost:2368",
"server": {
"port": 2368,
"host": "127.0.0.1"
}
}
I managed to figure out how to do this.
Here is the solution incase if someone else is also trying to figure out how to do the same thing.
In your config.development.json file, add the following.
{
"url": "http://{workspace_name}-{username}.c9users.io:8080",
"server": {
"port": 8080,
"host": "0.0.0.0"
}
}
Alternatively, run the following command in the terminal. This will dynamically get the value for the port and host environment variable and add the above content to the config.development.json file.
ghost config url http://$C9_HOSTNAME:$PORT
ghost config server.port $PORT
ghost config server.host $IP

Nightwatch tests to work on edge

I'm trying to get nightwatch tests to work in Microsoft edge. I'm getting an error saying connection refused. What's the right configuration to get tests to work on edge? Windows 10 edge 13
Could you post your configuration?
Make sure you have installed microsoft edge webdriver (you may download it here https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/).
You have to specify path to your edge driver using webdriver.edge.driver param, ex.
"selenium": {
"start_process": true,
"server_path": "./node_modules/file_dependencies/selenium-server-standalone.jar",
"log_path": "",
"host": "127.0.0.1",
"port": seleniumPort,
"cli_args": {
"webdriver.chrome.driver": "./node_modules/file_dependencies/chromedriver.exe",
"webdriver.ie.driver": "./node_modules/file_dependencies/IEDriverServer.exe",
"webdriver.edge.driver": "C:/Program Files (x86)/Microsoft Web Driver/MicrosoftWebDriver.exe",
"webdriver.gecko.driver": "./node_modules/file_dependencies/geckodriver.exe",
"webdriver.firefox.profile": ""
}
}
and example capabilities
"edge": {
"desiredCapabilities": {
"browserName": "MicrosoftEdge",
"javascriptEnabled": true,
"acceptSslCerts": true,
"pageLoadStrategy": "eager"
}
}

Resources