This plugin supprots only Hapi
subdomains plugin adds subdomains & subdomain properties to request object
// file: server.js
const subdomains = require("subdomains");
server.register({
plugin: subdomains,
options: {
// provide domain name for better results
domainName: "yourdomain.co.in",
// provide subdomains to exclude
// or an empty array
exclude: ["www", "api"]
}
});
http://users.kiprosh.trackive.com
// file server.js
"use strict";
const subdomains = require("subdomains");
const Hapi = require("hapi");
// Create a server with a host and port
const server = Hapi.server({
host: "localhost",
port: 8000
});
// Add the route
server.route({
method: "GET",
path: "/",
handler: (request, reply) => {
console.log(request.subdomains); // ['users', 'kiprosh']
console.log(request.subdomain); // 'users'
return "Home";
}
});
server.register({
plugin: subdomains,
options: {
// provide domain name for better results
domainName: "trackive.com",
// provide subdomains to exclude
// or an empty array
exclude: ["www", "api"]
}
});
// Start the server
async function start() {
try {
await server.start();
} catch (err) {
console.log(err);
process.exit(1);
}
console.log("Server running at:", server.info.uri);
}
start();
Whether you are a novice or experienced software developer, all contributions and suggestions are welcome!
-
Clone repo
git clone https://github.com/vemarav/subdomains.git
-
Add features or bug fixes
-
Make a Pull Request
OR
Report a bug here
Feel free to contribute, hosted on ❤️ with Github.
Package published under MIT License