Making an authenticated proxy request with Go? - http

I basically have a proxy that has a username and password. I was wondering how to make an HTTP request with the library net/http, but with an HTTP proxy with authentication.
Thank you!

What about something like
&http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(&url.URL{
Scheme: "http",
User: url.UserPassword("login", "password"),
Host: "IP:PORT",
}),
},
}

Related

TypeORM + Express deployed to firebase cloud function cannot connect to Cloud SQL

I tried to deploy a typeorm express server to Cloud Function for Firebase.
ormconfig:
{
type: "postgres",
username: [username],
password: [password],
database: [dbname],
extra: {
socketPath: `/cloudsql/[INSTANCE_CONNECTION_NAME]`,
},
synchronize: false,
dropSchema: false,
logging: true,
}
(values inside brackets are placeholders)
After deployed, the log complains about
TypeORM connection error: Error: connect ECONNREFUSED 127.0.0.1:5432
I don't understand why the DB address turned to 127.0.0.1? Did I miss something?
host should be specified in you ormconfig.json, if you did not use a default port for you db instance, port also required. And please make sure your ormconfig.json is valid json format
{
"type": "mysql",
"host": "localhost",
"port": 3306,
"username": "test",
"password": "test",
"database": "test",
"host": "localhost"
}
You also need to set the host value to /cloudsql/project:region:instance along with the socketPath

Redirect to other address if main address is unavailable in Ocelot Gateway API

I'd like to use Ocelot Gateway Api to connect to server, but if server is unavailable (e.g. PC is offline), I want to use local service instead.
For example, if first localhost:7001 failed, use localhost:7002.
{
"Routes": [
{
"DownstreamPathTemplate": "/catalog",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7001
},
{
"Host": "localhost",
"Port": 7002
}
],
"UpstreamPathTemplate": "/catalog-api"
}
],
"GlobalConfiguration": {
"BaseUrl": "http://localhost:7000"
}
}
Is such thing even possible?
Yes, it is perfectly possible. Ocelot supports load-balancing natively. In fact, by specifying multiple downstream paths, Ocelot will automatically load balance to the service which has the fewest number of active connections.
To have more control over the load-balancer functionality, you can specify the loadBalancerType property:
{
"Routes": [
{
"DownstreamPathTemplate": "/catalog",
"DownstreamScheme": "http",
"LoadBalancerOptions": {
"Type": "<<load balancer type here>>"
},
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7001
},
{
"Host": "localhost",
"Port": 7002
}
],
"UpstreamPathTemplate": "/catalog-api"
}
]
}
From the docs:
The type of load balancer available are:
LeastConnection - tracks which services are dealing with requests and sends new requests to service with least existing requests. The
algorythm state is not distributed across a cluster of Ocelot’s.
RoundRobin - loops through available services and sends requests. The algorythm state is not distributed across a cluster of
Ocelot’s.
NoLoadBalancer - takes the first available service from config or service discovery.
CookieStickySessions - uses a cookie to stick all requests to a specific server
From this is seems like the one you want is paradoxically called "NoLoadBalancer".
Reference: https://ocelot.readthedocs.io/en/latest/features/loadbalancer.html

Meteor app on digitalocean with https://app and https//www. Sometimes fails to serve https://app

Problem:
My app runs on digitalocean droplet with multiple domains:
proxy: {
domains: 'example.com,www.example.com',
ssl: {
letsEncryptEmail: '#'
}
}
Sometimes, for about half an hour the https://example.com fails to load completely but indirect links like https://example.com/about works fine.
Tried:
fiddling with nginx option:
nginxServerConfig: './nginx.conf',
Any attempts with it failed loading page completely
Mup.js file:
module.exports = {
servers: {
one: {}
},
app: {
deployCheckWaitTime: 300,
name: 'example',
path: '../',
buildOptions: {
serverOnly: true,
},
env: {
ROOT_URL: 'https://example.com',
MONGO_URL: 'mongodb://mongodb:27017/example',
},
docker: {
image: 'abernix/meteord:node-8.4.0-base',
args: ['--link=mongodb:mongodb'],
},
enableUploadProgressBar: true
},
proxy: {
domains: 'example.com,www.example.com',
ssl: {
letsEncryptEmail: '#'
}
}
};
Turns out, that problem lied in mailgun.
The mailgun DNS records didn't match v=spf1 include:eu.mailgun.org ~all thus those mails weren't authorized and whenever mail was sent through the system it was tripping domain provider to refresh it's DNS.
I solved this issue by setting up a permanent redirect for www through my domain settings.

Ghost config.js file

I m actually trying to create a simple blog using ghost, and I m facing a problem when starting in production envrionnement.
I m having the v0.7.1 and here's my config file (production part)
production: {
url: 'http://<my-public-ip>',
mail: {},
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost.db')
},
debug: false
},
server: {
host: '127.0.0.1',
port: '2368'
}
}
The fact is that when I try to access my public IP on a browser, I cant get anything at all on the screen(404 not found), even if I try on the 2368 port.
My firewall rules are well set.
what am I doing wrong ?
In the server object the host should be 0.0.0.0
server: {
host: '0.0.0.0',
port: '2368'
}
In the server object change the host .
host: '127.0.0.1', --> host: '0.0.0.0'
now start the ghost server by
npm start --production

Connect remote RabbitMq server

I am using RabbitMQ server for send message in my Symfony2 application.
I have used OldSoundRabbitMqBundle for this.
After successful installation of RabbitMq server on my application server it is working fine.
But when I install RabbitMQ server on different machine and try to connect it from my application server it is not connecting.
I have given the connection config as follows:
old_sound_rabbit_mq:
connections:
default:
host: myrabbitserverIp
port: 80
user: 'test'
password: 'test'
vhost: '/'
lazy: false
producers:
messages:
connection: default
exchange_options: {name: 'messages', type: direct}
consumers:
messages:
connection: default
exchange_options: {name: 'messages', type: direct}
queue_options: {name: 'messages'}
callback: message.amqp_consumer
Do I need to change any configuration for RabbitMq server?

Resources