This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
81 lines (67 loc) · 1.7 KB
/
app.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
74
75
76
77
78
79
80
81
const Io = require('socket.io')
, path = require('path')
, fs = require('fs')
, express = require('express')
, params = require('./params')
, debug = require('debug')('server')
, app = express()
, twitto = {
controller: {}
, meta: {
searchHashtags: []
}
, model: {}
, router: {}
}
const server = require('http').Server(app)
// set the view engine to ejs
app.set('view engine', 'ejs')
app.set('views', path.resolve(__dirname + '/view'))
app.use(express.static( __dirname + '/public'))
app.disable('x-powered-by')
// launch express server
server.listen(params.port)
console.log('Express server started')
// Render home page to static file
app.render('pages/index', {
appMeta : params.content.appMeta
, logo: params.content.logo
, appText: params.content.appText
, ga: params.googleAnalytics
, monitor: params.monitor.description
}, function(err, res) {
if (err)
console.log('Error rendering index.html', err)
else {
fs.writeFile(__dirname + '/public/index.html', res, function(err, res) {
if (err)
console.log('error saving index.html file', err)
})
}
})
// index page route
app.get('/', function (req, res) {
res.render('pages/index', {
appMeta : params.content.appMeta
, logo: params.content.logo
, appText: params.content.appText
, ga: params.googleAnalytics
, monitor: params.monitor.description
})
})
// Redirect all requests to home page instead of 404
app.use(function(req, res, next){
// respond with html page
if (req.accepts('html')) {
res.redirect(301, '/')
return
}
res.status(404)
// respond with json
if (req.accepts('json')) {
res.send({ error: 'Not found' })
return
}
// default to plain-text. send()
res.type('txt').send('Not found')
})