Skip to content

Static content served on other subdomains #39

@SplitPixl

Description

@SplitPixl

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions