edwardhotchkiss / subdomain Goto Github PK
View Code? Open in Web Editor NEWNode.JS Express Subdomain Middleware.
License: MIT License
Node.JS Express Subdomain Middleware.
License: MIT License
I'm giving the plugin a tire kick and it doesn't seem to work (for localhost). I have the subdomain added to my /etc/hosts file.
contact.localhost:3000
just routes to '/' ignoring the middleware I gave it to follow.
This is my code:
...
var subdomain = require('subdomain');
app.use(subdomain({ base : 'localhost', removeWWW : true }));
app.get('/subdomain/contact/', contactController.getContact);
...
Thanks in advance.
Hi, I just started using Koa.js for testing purposes but couldn't find a way to test sub-domains so I ported the code for Koa. If interested, I created a gist here. It seems to work as the original in my mocha tests but I cannot guarantee. Anyways, happy coding!
I don't know if this is a bug or just something happening with the way I have implemented the module but it looks like the headers can get sent more than once when forcing no www when you try to go to www.domain.com. It looks like this is due to line 25 when it i redirecting and then calling next(). Thinking this would be fixed by changing the code to use a return on the redirect and removing the next() call like so:
// remove 'www' prefix from URL? (tacky, right?)
if (options.removeWWW === true) {
if (/^www/.test(host)){
return response.redirect(protocol + '://' + host.replace(/^www\./, '') + request.url);
//next();
};
};
Hi there,
thanks for the plugin :) I am trying it out, but while I can get it to work on localhost I can't get it to work on a hosted domain.
server DNS address could not be found
I use an env variable to set-up the base domain like so: base: process.env.DOMAIN || 'localhost'
Any idea how to solve this issue?
Is it possible to use regex in subdomain?
Example:
subdomain = '/subdomain/blog';
router.get(new RegExp(subdomain.replace(/\//g, '\\/') + "\\/((test|tester|tests)\\/?)$"), function(req, res) {
res.send('hello world');
});
Great subdomain middleware! Thanks.
by the way, Do you support express.static?
http://expressjs.com/en/starter/static-files.html
expect:
app.use('/subdomain/resources/', express.static(`${__dirname}/resources`));
Sorry my English. thanks.
I would like to ignore specific subdomains so that it doesn't use the functionality of this module. Is this possible?
Hi, I'm having an issue where I cant use an IP address for my Staging.
My staging site only has an IP and not a domain name.
Any suggestions?
using localhost doesn't work
Hi @edwardhotchkiss i would like to know how i can try it in localhost. It's possibile? Because at the moment I didn't have success.
Thanks in advance. =)
NPM complains about your version number and thus I can't install the package.
Here's a related SO question: http://stackoverflow.com/questions/16887993/npm-why-is-a-version-0-1-invalid
Can you fix this? Thanks!
Any thoughts on this? Am I the only one that's seeing this?
This is being caught in: config/routes.js#completeRegistration
slide-server-server-21 (err): TypeError: Cannot call method 'match' of undefined
slide-server-server-21 (err): at Layer.handle (/home/gmike/projects/slide-server/src/server2/node_modules/subdomain/lib/subdomain.js:41:26)
slide-server-server-21 (err): at trim_prefix (/home/gmike/projects/slide-server/src/server2/node_modules/express/lib/router/index.js:226:17)
slide-server-server-21 (err): at c (/home/gmike/projects/slide-server/src/server2/node_modules/express/lib/router/index.js:198:9)
slide-server-server-21 (err): at Function.proto.process_params (/home/gmike/projects/slide-server/src/server2/node_modules/express/lib/router/index.js:251:12)
slide-server-server-21 (err): at next (/home/gmike/projects/slide-server/src/server2/node_modules/express/lib/router/index.js:189:19)
slide-server-server-21 (err): at Layer.methodOverride as handle
slide-server-server-21 (err): at trim_prefix (/home/gmike/projects/slide-server/src/server2/node_modules/express/lib/router/index.js:226:17)
slide-server-server-21 (err): at c (/home/gmike/projects/slide-server/src/server2/node_modules/express/lib/router/index.js:198:9)
slide-server-server-21 (err): at Function.proto.process_params (/home/gmike/projects/slide-server/src/server2/node_modules/express/lib/router/index.js:251:12)
slide-server-server-21 (err): at next (/home/gmike/projects/slide-server/src/server2/node_modules/express/lib/router/index.js:189:19)
Hi,
I can't seem to access my public directory when the URL includes the subdomain. For example,
http://sub.host.com/css/style.css
won't route me to my public directory. So right now I've been using middleware to redirect. in my app.js i have:
app.use(express.static(__dirname
+ '/public'));
Even though the 'host' header is mandatory, if your server is being attacked maliciously that header isn't always set. So we should check if it's truthy before using it.
Otherwise this is the error:
TypeError: Cannot call method 'match' of undefined
at /usr/src/project/node_modules/subdomain/lib/subdomain.js:41:26
I'm trying to use this inside a router but doesn't seems to work.
Can you provide a working example?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.