Search code examples
expressurldnssubdirectory

Express DNS not directing to subdirectories


When I am on

127.0.0.1:8081

and I click a link that has an href of /mod it takes me to

127.0.0.1:8081/mods

But now I am using a DNS that simply redirects to my IP, but instead of changing the sub directory, it stays the same. The page that my web server is programmed to send still sends, but the URL doesn't. This means that when I refresh on the URL it takes me back to the index. There are no errors per say, but it is not doing what I want it to do.

This is the web server (Express)

var express = require('express')
var app = express()
var path = require('path')
var favicon = require('serve-favicon')

app.use(express.static(path.join(__dirname, 'public'))) //Loads all files in public (Used for css and js inside of html)

//Home page
app.get('/', function(req, res, next) {
  var options  = {
    root: 'public'
  }
  res.sendFile('index.html', options, function (err) {
    if (err) {
      next(err)
    }
  })
})

app.get('/mods', function(req, res, next) {
  var options  = {
    root: 'public'
  }
  res.sendFile('mods.html', options, function (err) {
    if (err) {
      next(err)
    }
  })
})

var server = app.listen(8080, function () {
   var host = server.address().address
   var port = server.address().port

   app.use(favicon(path.join(__dirname, 'public', 'icon.ico')))

   console.log(`Example app listening at http://127.0.0.1:${port}`)
})

And this is the html file, and how I change directory.

<!DOCTYPE html>
<html>
<head>
  <title>Multiplex InterFree</title>
  <link href="/styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
  <div class="nav-bar">
    <img src="/icon.jpg" width="90px" height="90px"/>
    <div class="buttons">
      <a href="#">Home</a>
      <a href="about">About</a>
    </div>
  </div>
  <br/>
  <br/>
  <br/>
  <br/>
  <br/>
  <br/>
  <br/>
  <div class="main">
    <h2>Welcome!</h2>
    <p>Multiplex InterFree is a 1.12.2 <a class="link" href="/mods">modded<a> anarchy server.</p>
  </div>
</body>
</html>


Solution

  • I found the answer through irl resources. instead of doing /mods, I needed to do

    myverycooliourl.com/mods

    Obviously the url before the / being your DNS' url.