forked from cosmic/cosmic-web
completed transition from web script to express proxy
This commit is contained in:
parent
b5f8a480f7
commit
37c618bd57
30
server.js
30
server.js
|
@ -121,8 +121,36 @@ app.get('/atom.xml', async function (req, res) {
|
|||
res.render('raw', { content: content })
|
||||
})
|
||||
|
||||
// Any link to a direct resource will show it
|
||||
// Any link to a direct static resource will show it
|
||||
app.use(express.static(path.join(__dirname, '/static')))
|
||||
|
||||
// Override default LICENSE display and format for cosmic styles
|
||||
app.get('*/LICENSE', function(req, res){
|
||||
let error = false
|
||||
var file = path.join('/var/gopher/', decodeURIComponent(req.path));
|
||||
fs.exists(file, function(exists) {
|
||||
if (exists) {
|
||||
const file = bufferFile('/var/gopher/' + decodeURIComponent(req.path))
|
||||
const back = '<a href="/log"><span class="dim"><<</span> BACK TO RS001 LOG</a>'
|
||||
const content = back + '\n\n' + file
|
||||
res.setHeader('content-type', 'text/html')
|
||||
res.render('basic', { content: content })
|
||||
} else {
|
||||
error = true
|
||||
}
|
||||
})
|
||||
|
||||
// If license isn't found, give the 404
|
||||
if (error) {
|
||||
const back = '<a href="/"><span class="dim"><<</span> BACK TO COSMIC VOYAGE</a>'
|
||||
const error = 'Message not found. Please try again.'
|
||||
const content = back + '\n\n' + error
|
||||
res.status(404)
|
||||
res.render('basic', { content: content })
|
||||
}
|
||||
})
|
||||
|
||||
// Any other gopher content directly linked will show as-is
|
||||
app.use(express.static('/var/gopher'))
|
||||
|
||||
// Grab anything that's a .txt and wrap it in .html
|
||||
|
|
Loading…
Reference in New Issue