-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
73 lines (67 loc) · 1.85 KB
/
server.js
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
var compression = require('compression');
const fs = require('fs')
const express = require('express')
const app = express()
const PORT = 3000
app.use(compression());
//app.use(express.static(__dirname + '/public', { maxAge: 31557600 }))
app.get('*', function(req, res, next) {
const host = req.headers.host
const fullUrl = req.url
let url = req.url.split('?')[0]
let urlParams = null
if (req.url.includes('?')) {
urlParams = '?' + req.url.split('?')[1]
}
const redirect = redirects.hasOwnProperty(url.toLowerCase())
console.log(redirect)
const other = url.includes('%20')
if (url.includes(' ')) {
url = url.split(' ').join('%20')
}
if (redirect) {
let newLocation
if (urlParams) {
newLocation = redirects[url.toLowerCase()] + urlParams
} else {
newLocation = redirects[url.toLowerCase()]
}
res.writeHead(301, {
Location: newLocation
})
res.end()
} else if (other) {
let newLocation
if (urlParams) {
newLocation = url.toLowerCase().split('%20').join('-') + urlParams
} else {
newLocation = url.toLowerCase().split('%20').join('-')
}
res.writeHead(301, {
Location: newLocation
})
res.end()
} else {
next()
}
}
)
// let counter = 100
// let data = ''
//
// function getProfileSiteMap(counter) {
// axios.get(`https://www.pulse.qa/sitemaps/sitemap_profile${counter}.xml.gz`).then((res) => {
// data = data + res.data
// fs.writeFileSync('profiles1.txt', data)
// console.log(counter)
// if(counter<=296) {
// setTimeout(() => {
// getProfileSiteMap(counter + 1)
// }, 1000)
// }
// }).catch((e)=>{
// console.log(e)
// })
// }
// getProfileSiteMap(counter)
app.listen(PORT, () => console.log(`Server listening on port: ${PORT}`))