This repository was archived by the owner on Feb 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
86 lines (70 loc) · 2.97 KB
/
app.js
File metadata and controls
86 lines (70 loc) · 2.97 KB
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
82
83
84
85
86
/*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Filename : base/app.js
Desc : main application file
Author(s): RAk3rman
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
// Packages and configuration - - - - - - - - - - - - - - - - - - - - - - - - -
// Declare packages
const path = require('path');
const dataStore = require('data-store');
const config_storage = new dataStore({path: './config/config.json'});
const chalk = require('chalk');
const pkg = require('./package.json');
const moment = require('moment');
const wipe = chalk.white;
// Print header to console
console.clear();
console.log(chalk.blue.bold('\nBase Webframework v' + pkg.version + ((process.argv[2] !== undefined) ? ' | ' + process.argv[2].toUpperCase() : "" )));
console.log(chalk.white('--> Contributors: ' + pkg.author));
console.log(chalk.white('--> Description: ' + pkg.description));
console.log(chalk.white('--> Github: ' + pkg.homepage + '\n'));
// Check configuration values
let setup = require('./config/setup.js');
setup.check_values(config_storage);
// End of Packages and configuration - - - - - - - - - - - - - - - - - - - - - -
// Fastify and main functions - - - - - - - - - - - - - - - - - - - - - - - - - -
// Declare fastify
const fastify = require('fastify')({logger: false});
// Prepare rendering template
fastify.register(require('point-of-view'), {
engine: {
handlebars: require('handlebars')
},
})
fastify.register(require('fastify-static'), {
root: path.join(__dirname, 'public'),
prefix: '/public/',
})
// fastify.register(require('fastify-socket.io'), {})
// fastify.register(require('fastify-formbody'))
// fastify.register(require('fastify-rate-limit'), {
// global: false,
// max: 250,
// timeWindow: '1 minute'
// })
// Routers
let error_routes = require('./routes/error-routes.js');
// Import routes
error_routes(fastify);
// Home page
fastify.get('/', (req, reply) => {
reply.view('/templates/home.hbs', {
title: "Home"
})
console.log(wipe(`${chalk.bold.magenta('Fastify')}: [` + moment().format('MM/DD/YY-HH:mm:ss') + `] GET /`));
})
// End of Fastify and main functions - - - - - - - - - - - - - - - - - - - - - -
// Setup external connections - - - - - - - - - - - - - - - - - - - - - - - - -
// Start webserver using config values
console.log(wipe(`${chalk.bold.magenta('Fastify')}: [` + moment().format('MM/DD/YY-HH:mm:ss') + `] Attempting to start http webserver on port ` + config_storage.get('webserver_port')));
fastify.listen(config_storage.get('webserver_port'), function (err) {
if (err) {
fastify.log.error(err)
process.exit(1)
}
console.log(wipe(`${chalk.bold.magenta('Fastify')}: [` + moment().format('MM/DD/YY-HH:mm:ss') + `] Running http webserver on port ` + config_storage.get('webserver_port')));
// Check if we are testing
const testing = require('./config/testing.js');
testing.testCheck();
})
// End of Setup external connections - - - - - - - - - - - - - - - - - - - - - -