-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
83 lines (74 loc) · 2.6 KB
/
server.js
File metadata and controls
83 lines (74 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const https = require('http')
const express = require('express')
const subdomain = require('express-subdomain')
const fs = require('fs')
const server = express()
const port = 3000
//Adds the "src" folder to the available server urls
server.use(express.static('src'));
server.use(express.static('objmap'))
/*
// Handles errors
server.use(function (err, req, res, next) {
console.warn(err.stack)
console.log('this is the error specific function, here is the error ' + err)
});
*/
const objmap = express.Router()
objmap.get('/', (req, res) => {
res.sendFile(`${__dirname}/objmap/dist/index.html`)
})
objmap.get('/:subDir/:subFile?', (req, res) => {
let subFile = req.params['subFile']
let subDir = req.params['subDir']
// console.log(subDir, subFile)
try {
if (subFile != undefined){
res.status(200).sendFile(`${__dirname}/objmap/dist/${subDir}/${subFile}`)
}
else {
res.status(200).sendFile(`${__dirname}/objmap/dist/${subDir}`)
}
}
catch {
res.status(404).sendFile(__dirname + '/src/404.html')
}
})
server.use(subdomain('objmap', objmap))
const radar = require('./routes/radar/app/app')
radar.get('/', (req, res) => {
res.status(404).sendFile(__dirname + '/src/404.html')
})
server.use(subdomain('radar', radar))
const api = require('./routes')()
server.use(subdomain('api', api))
// Sends any requests to the base url to the index page
server.get('/', (req, res) => {
if (req.hostname.split('.')[0] === 'www' || req.hostname.split('.')[0] === 'relicsofthepast'){
res.sendFile(__dirname + '/src/home.html')
}
else {
res.status(404).sendFile(`${__dirname}/src/404.html`)
}
});
// Sends the user to the hidden place, this is setup separately in case we want some extra functionality added to the page
server.get('/hidden', (req, res) => {
console.log(__dirname)
res.sendFile(`${__dirname}/src/hidden.html`)
});
// Attempts to forward any requests from /{var} to a corresponding HTML page
server.get('/:pageName', (req, res) => {
var pageName = req.params['pageName']
var page = `${__dirname}/src/${pageName.toLowerCase()}.html`
console.log(page)
if (fs.existsSync(page) && (req.hostname.split('.')[0] === 'www' || req.hostname.split('.')[0] === 'relicsofthepast')) {
res.sendFile(page)
}
else {
res.status(404).sendFile(`${__dirname}/src/404.html`)
};
});
// Starts the server
server.listen(port, 'localhost', () => {
console.log(`Server started on localhost:${port}`)
});