हैपी के साथ प्राप्त करने का एक अच्छा तरीका आपकी अलग-अलग साइटों को plugins को अलग करने और प्लगइन लोड करते समय vhost
संशोधक का उपयोग करके आदर्श रूप से Glue का उपयोग कर रहा है।
यहाँ एक उदाहरण है:
साइटों/dogs.js
exports.register = function (server, options, next) {
// Put all your routes for the site in here
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply('Dogs homepage');
}
});
next();
};
exports.register.attributes = { name: 'dogs' };
साइटों/cats.js
exports.register = function (server, options, next) {
// Put all your routes for the site in here
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply('Cats homepage');
}
});
next();
};
exports.register.attributes = { name: 'cats' };
index.js
const Glue = require('glue');
const Hoek = require('hoek');
const manifest = {
connections: [{
port: 4000,
}],
registrations: [
{
plugin: {
register: './sites/cats'
},
options: {
routes: {
vhost: 'cats.com'
}
}
},
{
plugin: {
register: './sites/dogs'
},
options: {
routes: {
vhost: 'dogs.com'
}
}
}
]
};
const options = {
relativeTo: __dirname
};
Glue.compose(manifest, options, (err, server) => {
Hoek.assert(!err, err);
server.start((err) => {
Hoek.assert(!err, err);
console.log('server started');
});
});
फिर आपको यह पुष्टि कर सकते हैं कि मार्ग cURL के एक जोड़े के साथ ठीक से काम करता आदेश:
$ curl -H "Host: cats.com" localhost:4000/
Cats homepage
$ curl -H "Host: dogs.com" localhost:4000/
Dogs homepage
एक ब्राउज़र आप के लिए है कि होस्ट हैडर सेट हो जाएगा, हालांकि ताकि आप http://cats.com को ब्राउज़ करें या http://dogs.com HAPI काम करेगा जब सही सामग्री (बशर्ते आपका DNS सही तरीके से कॉन्फ़िगर किया गया हो)।
स्रोत
2016-02-29 11:54:03
मैं टेम्पलेट्स कैसे सेवा करूं? – eosimosu