You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.2 KiB
74 lines
2.2 KiB
// countdown.js
|
|
// Copyright (C) 2022 DTP Technologies, LLC
|
|
// License: Apache-2.0
|
|
|
|
'use strict';
|
|
|
|
require('dotenv').config();
|
|
|
|
const path = require('path');
|
|
|
|
const express = require('express');
|
|
const multer = require('multer');
|
|
|
|
module.postCreateCountdown = async (req, res, next) => {
|
|
const date = req.body.date.split('-');
|
|
const time = req.body.time.split(':');
|
|
res.locals.params = {
|
|
show: {
|
|
title: req.body.title,
|
|
url: req.body.url,
|
|
},
|
|
year: date[0],
|
|
month: date[1],
|
|
date: date[2],
|
|
hours: time[0],
|
|
minutes: time[1],
|
|
};
|
|
res.render('countdown/created');
|
|
};
|
|
|
|
module.getTimerView = async (req, res) => {
|
|
res.render('countdown/timer');
|
|
};
|
|
|
|
module.getHomeView = async (req, res) => {
|
|
res.render('index');
|
|
};
|
|
|
|
(async ( ) => {
|
|
module.app = express();
|
|
|
|
module.app.locals.moment = require('moment');
|
|
module.app.locals.numeral = require('numeral');
|
|
module.app.locals.site = {
|
|
domain: process.env.DTP_SITE_DOMAIN || 'localhost:8000',
|
|
};
|
|
|
|
module.app.set('view engine', 'pug');
|
|
module.app.set('views', path.join(__dirname, 'app', 'views'));
|
|
|
|
module.app.use('/uikit', express.static(path.join(__dirname, "node_modules", "uikit", "dist")));
|
|
module.app.use('/moment', express.static(path.join(__dirname, "node_modules", "moment", "min")));
|
|
module.app.use('/numeral', express.static(path.join(__dirname, "node_modules", "numeral", "min")));
|
|
|
|
module.app.use('/fonts', express.static(path.join(__dirname, 'client', 'fonts')));
|
|
module.app.use('/css', express.static(path.join(__dirname, 'client', 'css')));
|
|
|
|
module.app.use(express.urlencoded({ extended: true }));
|
|
|
|
const upload = multer();
|
|
module.app.post('/', upload.none(), module.postCreateCountdown);
|
|
|
|
module.app.get('/timer', module.getTimerView);
|
|
module.app.get('/', module.getHomeView);
|
|
|
|
const bind = {
|
|
host: process.env.DTP_HTTP_HOST || 'localhost',
|
|
port: parseInt(process.env.DTP_HTTP_PORT || '8000', 10),
|
|
};
|
|
console.log('starting service', bind);
|
|
module.app.listen(bind.port, bind.host, ( ) => {
|
|
console.log('Countdown online');
|
|
});
|
|
})();
|