So I have run into a problem with content on subdomains that shouldn't be there being there.
Let's assume that I have a folder of static content that should only be served on example.com. In this folder I have a file foo.png
I will be using this code:
app.js:
// deps and stuff
app.use(express.static(path.join(__dirname, 'static')));
fs.readdirSync('./modules').forEach((mod, index, array) => {
if(mod.endsWith('.js')) {
let name = mod.substring(0, mod.length - 3)
console.log(`Loaded module: ${name}`)
app.use(subdomain(name, require(`./modules/${mod}`)))
}
})
// other server stuff
modules/test.js
//deps n stuff
router.get('/', (req, res, next) => {
res.send("Hi, this test worked.");
});
module.exports = router
I would expect http://example.com/foo.png to return the picture, which it does.
I would also expect http://test.example.com/foo.png to return a 404 not found, but it returns foo.png as well.
How would I get my static content to only show on the domain example.com?
I tried app.use(subdomain('', staticContentRouter)) but it throws an error.
So I have run into a problem with content on subdomains that shouldn't be there being there.
Let's assume that I have a folder of static content that should only be served on
example.com. In this folder I have a filefoo.pngI will be using this code:
app.js:
modules/test.js
I would expect
http://example.com/foo.pngto return the picture, which it does.I would also expect
http://test.example.com/foo.pngto return a 404 not found, but it returns foo.png as well.How would I get my static content to only show on the domain
example.com?I tried
app.use(subdomain('', staticContentRouter))but it throws an error.