first posts
This commit is contained in:
27
src/log.ts
27
src/log.ts
@ -1,6 +1,5 @@
|
||||
import * as moment from 'moment'
|
||||
import * as config from './config'
|
||||
import * as nodemailer from 'nodemailer'
|
||||
|
||||
|
||||
enum Level {
|
||||
@ -25,32 +24,6 @@ export function setLevel(value: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
export function sendAlarmMail(subject : string, message : string): void {
|
||||
let transport = nodemailer.createTransport({
|
||||
host: config.dict.smtpHost,
|
||||
port: config.dict.smtpPort,
|
||||
secure: false,
|
||||
tls: {
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
});
|
||||
|
||||
let mail : nodemailer.SendMailOptions = {
|
||||
from: config.dict.smtpSender,
|
||||
to: config.dict.smtpReceiver,
|
||||
subject: subject,
|
||||
text: message
|
||||
};
|
||||
|
||||
transport.sendMail(mail)
|
||||
.then((v : nodemailer.SentMessageInfo) => {
|
||||
info(`Mail sent, ${subject}, ${message}, ${v.response}`)
|
||||
})
|
||||
.catch((reason : any) => {
|
||||
error(`Failure when sending alarm mail: ${message}, ${reason}`)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
export function info(message: string): void {
|
||||
if (level < Level.NoDebugNoInfo) {
|
||||
|
15
src/main.ts
15
src/main.ts
@ -18,12 +18,19 @@ app.engine('pag', (filePath: string, options: any, callback: any) => {
|
||||
if (err) {
|
||||
return callback(new Error(err.message))
|
||||
}
|
||||
let renderedPhase1 = content.toString()
|
||||
|
||||
let contentStr = content.toString()
|
||||
let pageOptionsStr = contentStr.replace(/^\s+<!-- (\{.*\}) -->.*$/, "\$1")
|
||||
logger.info(`contentStr: ${contentStr}`)
|
||||
logger.info(`pageOptionsStr: ${pageOptionsStr}`)
|
||||
let pageOptions = JSON.parse(pageOptionsStr)
|
||||
let renderedPhase1 = contentStr
|
||||
.replace('#bla#', 'blu')
|
||||
|
||||
let renderedPhase2 = masterTmpl
|
||||
.replace('#maincontent#', renderedPhase1)
|
||||
.replace('#title#', options.title)
|
||||
.replace('#title#', pageOptions.title)
|
||||
|
||||
return callback(null, renderedPhase2)
|
||||
})
|
||||
})
|
||||
@ -35,6 +42,10 @@ app.get('/index', (req, res) => {
|
||||
res.render('index', {'title': 'Projects - just for fun'})
|
||||
})
|
||||
|
||||
app.get('/posts/:date', (req, res) => {
|
||||
res.render(`posts/${req.params.date}/article`, {})
|
||||
})
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Hello world!')
|
||||
})
|
||||
|
Reference in New Issue
Block a user