Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
grunt-connect-proxy
Advanced tools
Provides a http proxy as middleware for the grunt-contrib-connect plugin.
This plugin requires Grunt ~0.4.1
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-connect-proxy --save-dev
One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-connect-proxy');
In your project's Gruntfile, add a section named proxies
to your existing connect definition.
grunt.initConfig({
connect: {
server: {
options: {
port: 9000,
hostname: 'localhost'
},
proxies: [
{
context: '/cortex',
host: '10.10.2.202',
port: 8080,
https: false,
xforward: false,
headers: {
"x-custom-added-header": value
}
}
]
}
}
})
Add the middleware call from the connect option middleware hook
connect: {
livereload: {
options: {
middleware: function (connect, options) {
if (!Array.isArray(options.base)) {
options.base = [options.base];
}
// Setup the proxy
var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest];
// Serve static files.
options.base.forEach(function(base) {
middlewares.push(connect.static(base));
});
// Make directory browse-able.
var directory = options.directory || options.base[options.base.length - 1];
middlewares.push(connect.directory(directory));
return middlewares;
}
}
}
}
It is possible to add the proxy middleware without Livereload as follows:
// server
connect: {
server: {
options: {
port: 8000,
base: 'public',
logger: 'dev',
hostname: 'localhost',
middleware: function (connect, options) {
var proxy = require('grunt-connect-proxy/lib/utils').proxyRequest;
return [
// Include the proxy first
proxy,
// Serve static files.
connect.static(options.base),
// Make empty directories browsable.
connect.directory(options.base)
];
}
},
proxies: [ /* as defined above */ ]
}
}
For the server task, add the configureProxies task before the connect task
grunt.registerTask('server', function (target) {
grunt.task.run([
'clean:server',
'compass:server',
'configureProxies:server',
'livereload-start',
'connect:livereload',
'open',
'watch'
]);
});
IMPORTANT: You must specify the connect target in the configureProxies
task.
The available configuration options from a given proxy are generally the same as what is provided by the underlying httpproxy library
Type: String
or Array
The context(s) to match requests against. Matching requests will be proxied. Should start with /. Should not end with / Multiple contexts can be matched for the same proxy rule via an array such as: context: ['/api', 'otherapi']
Type: String
The host to proxy to. Should not start with the http/https protocol.
Type: Number
Default: 80
The port to proxy to.
Type: Boolean
Default: false
Whether to proxy with https
Type: Boolean
Default: false
Whether to add x-forward headers to the proxy request, such as "x-forwarded-for": "127.0.0.1", "x-forwarded-port": 50892, "x-forwarded-proto": "http"
Type: Boolean
Default: true
Set to false to isolate multi-task configuration proxy options from parent level instead of appending them.
Type: Object
Allows rewrites of url (including context) when proxying. The object's keys serve as the regex used in the replacement operation. As an example the following proxy configuration will remove the context when proxying:
proxies: [
context: '/context',
host: 'host',
port: 8080,
rewrite: {
'^/removingcontext': '',
'^/changingcontext': '/anothercontext'
}
]
Type: Object
A map of headers to be added to proxied requests.
Type: Boolean
Default: false
Set to true to proxy websockets.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
grunt-contrib-connect multi-server configuration is supported. You can define proxies blocks in per-server options and refer to those blocks in task invocation.
grunt.initConfig({
connect: {
options: {
port: 9000,
hostname: 'localhost'
},
server2: {
proxies: [
{
context: '/cortex',
host: '10.10.2.202',
port: 8080,
https: false,
}
]
},
server3: {
appendProxies: false,
proxies: [
{
context: '/api',
host: 'example.org'
}
]
}
}
})
grunt.registerTask('e2etest', function (target) {
grunt.task.run([
'configureProxies:server2',
'open',
'karma'
]);
});
FAQs
Provides a http proxy as middleware for grunt connect.
The npm package grunt-connect-proxy receives a total of 1,874 weekly downloads. As such, grunt-connect-proxy popularity was classified as popular.
We found that grunt-connect-proxy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.