change approach again
This commit is contained in:
48
src/main.ts
Normal file
48
src/main.ts
Normal 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")
|
||||
|
Reference in New Issue
Block a user