Reputation: 711
I have a API written in Node JS Express JS. I used apidocjs.com to generate the static content. The problem i am having is i want the docs file to be under a subdomain docs.example.com or api.example.com/docs if that is the best practice?
app.use(express.static(__dirname + '/public'));
app.use(express.static(__dirname + '/docs/api'));
app.use('/v1', subdomain('api', require('./controller/api_v1')(stormpath, log)));
app.use(subdomain('docs', require('./controller/docs')(stormpath, log)));
app.use(require('./controller/index')(stormpath, log));
This works if i change the index.html in docs/api to start.html. So the last problem is how to stop express JS to start the index.html if i do not want it to?
Upvotes: 0
Views: 1786
Reputation: 711
So i did it :)
Here is how. I used this lib to handel subdomain express-subdomain
"APP.JS"
app.use(express.static(__dirname + '/docs/api', {
index: false,
redirect: false
}));
app.use(subdomain('docs', require('./controller/docs')(log)));
"docs/api"
res.sendFile(path.join(__dirname+'/../docs/api/index.html'));
Upvotes: 0
Reputation: 30330
http://api.example.com/docs
is easily confused for an API resource called docs
.
http://docs.example.com/
avoids that ambiguity so it is probably a better choice.
Upvotes: 2