change approach again

This commit is contained in:
2018-05-09 14:31:22 +02:00
parent 54a933c83a
commit 0686e02b75
2252 changed files with 864743 additions and 270 deletions

48
src/main.ts Normal file
View File

@ -0,0 +1,48 @@
import * as fs from 'fs'
import * as config from './config'
import * as logger from './log'
import * as express from 'express'
logger.info("Homepage starting")
let app = express()
let masterTmpl: string
app.engine('pag', (filePath: string, options: any, callback: any) => {
fs.readFile(filePath, (err, content) => {
if (err) {
return callback(new Error(err.message))
}
let renderedPhase1 = content.toString()
.replace('#bla#', 'blu')
let renderedPhase2 = masterTmpl
.replace('#maincontent#', renderedPhase1)
.replace('#title#', options.title)
return callback(null, renderedPhase2)
})
})
app.set('views', './docroot')
app.set('view engine', 'pag')
app.get('/index', (req, res) => {
res.render('index', {'title': 'Projects - just for fun'})
})
app.get('/', (req, res) => {
res.send('Hello world!')
})
masterTmpl = fs.readFileSync(config.dict.masterTmpl).toString()
app.listen(config.dict.httpPort, () => {
logger.info("Homepage is listening")
})
logger.info("Homepage running")