Repository navigation
Expand file tree
/
Copy pathconfig.js
More file actions
107 lines (92 loc) · 3.01 KB
/
Copy pathconfig.js
File metadata and controls
107 lines (92 loc) · 3.01 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// @themost-framework 2.0 Codename Blueshift Copyright (c) 2017-2025, THEMOST LP All rights reserved
var ConfigurationBase = require('@themost/common').ConfigurationBase;
var TraceUtils = require('@themost/common').TraceUtils;
var PathUtils = require('@themost/common').PathUtils;
var Symbol = require('symbol');
var _ = require('lodash');
var routesProperty = Symbol('routes');
class HttpConfiguration extends ConfigurationBase {
/**
* @class
* @constructor
* @param {string} configPath
* @augments ConfigurationBase
*/
constructor(configPath) {
super(configPath);
if (!this.hasSourceAt('mimes')) { this.setSourceAt('mimes',[]); }
if (!this.hasSourceAt('engines')) { this.setSourceAt('engines',[]); }
if (!this.hasSourceAt('controllers')) { this.setSourceAt('controllers',[]); }
if (!this.hasSourceAt('handlers')) { this.setSourceAt('handlers',[]); }
try {
this[routesProperty] = require(PathUtils.join(this.getConfigurationPath(),'routes.json'))
}
catch(err) {
if (err.code === 'MODULE_NOT_FOUND') {
this[routesProperty] = require('./resources/routes.json');
}
else {
TraceUtils.error('An error occurred while loading routes collection');
TraceUtils.error(err);
}
}
/**
* @name HttpConfiguration#engines
* @type {Array.<HttpViewEngineConfiguration>}
*/
Object.defineProperty(this, 'engines', {
get:function() {
return this.getSourceAt('engines');
}
});
/**
* @name HttpConfiguration#mimes
* @type {Array.<MimeTypeConfiguration>}
*/
Object.defineProperty(this, 'mimes', {
get:function() {
return this.getSourceAt('mimes');
}
});
/**
* @name HttpConfiguration#routes
* @type {Array.<HttpRouteConfiguration>}
*/
Object.defineProperty(this, 'routes', {
get:function() {
return this[routesProperty];
}
});
/**
* @name HttpConfiguration#controllers
* @type {Array}
*/
Object.defineProperty(this, 'controllers', {
get:function() {
return this.getSourceAt('controllers');
}
});
/**
* @name HttpConfiguration#handlers
* @type {Array.<HttpHandlerConfiguration>}
*/
Object.defineProperty(this, 'handlers', {
get:function() {
return this.getSourceAt('handlers');
}
});
}
/**
* Gets a mime type based on the given extension
* @param {string} extension
* @returns {*}
*/
getMimeType(extension) {
return _.find(this.mimes,function(x) {
return (x.extension===extension) || (x.extension==='.'+extension);
});
}
}
module.exports = {
HttpConfiguration
}