5htp-core 0.1.2-1 → 0.1.2-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/client/assets/css/medias.less +14 -0
- package/src/server/app/config.ts +1 -17
- package/src/server/app/index.ts +1 -1
- package/src/server/libs/pages/document.tsx +1 -1
- package/src/server/services/auth/base.ts +18 -11
- package/src/server/services/console/index.ts +11 -2
- package/src/server/services/email/index.ts +1 -1
- package/src/server/services/http/index.ts +14 -28
- package/src/server/services/router/request/index.ts +0 -2
- package/src/server/services/router/request/services/detect.ts +2 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "5htp-core",
|
|
3
3
|
"description": "5-HTP, scientifically called 5-Hydroxytryptophan, is the precursor of happiness neurotransmitter.",
|
|
4
|
-
"version": "0.1.2-
|
|
4
|
+
"version": "0.1.2-3",
|
|
5
5
|
"author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
|
|
6
6
|
"repository": "git://github.com/gaetanlegac/5htp-core.git",
|
|
7
7
|
"license": "MIT",
|
|
@@ -8,6 +8,20 @@ img.img,
|
|
|
8
8
|
.bg.img {
|
|
9
9
|
.build-theme-bg(#000, #fff);
|
|
10
10
|
text-shadow: 0 0 10px fade(#000, 20%);
|
|
11
|
+
|
|
12
|
+
--cTxtDiscret: fade(#fff, 40%)
|
|
13
|
+
--cTxtDesc: fade(#fff, 60%);
|
|
14
|
+
--cTxtBase: fade(#fff, 80%);
|
|
15
|
+
--cTxtImportant: fade(#fff, 100%);
|
|
16
|
+
--cTxtAccent: fade(#fff, 20%);
|
|
17
|
+
|
|
18
|
+
&.light {
|
|
19
|
+
--cTxtDiscret: fade(#000, 40%)
|
|
20
|
+
--cTxtDesc: fade(#000, 60%);
|
|
21
|
+
--cTxtBase: fade(#000, 80%);
|
|
22
|
+
--cTxtImportant: fade(#000, 100%);
|
|
23
|
+
--cTxtAccent: fade(#000, 20%);
|
|
24
|
+
}
|
|
11
25
|
}
|
|
12
26
|
|
|
13
27
|
img {
|
package/src/server/app/config.ts
CHANGED
|
@@ -30,14 +30,8 @@ declare global {
|
|
|
30
30
|
|
|
31
31
|
export type TEnvName = TEnvConfig["name"];
|
|
32
32
|
export type TEnvConfig = {
|
|
33
|
-
|
|
34
33
|
name: 'local' | 'server',
|
|
35
34
|
profile: 'dev' | 'prod',
|
|
36
|
-
level: 'silly' | 'info' | 'warn' | 'error',
|
|
37
|
-
|
|
38
|
-
localIP: string,
|
|
39
|
-
domain: string,
|
|
40
|
-
url: string,
|
|
41
35
|
}
|
|
42
36
|
|
|
43
37
|
type AppIdentityConfig = {
|
|
@@ -93,20 +87,10 @@ export default class ConfigParser {
|
|
|
93
87
|
console.log("Using environment:", process.env.NODE_ENV);
|
|
94
88
|
return process.env.NODE_ENV === 'development' ? {
|
|
95
89
|
name: 'local',
|
|
96
|
-
profile: 'dev'
|
|
97
|
-
level: 'silly',
|
|
98
|
-
|
|
99
|
-
localIP: '86.76.176.80',
|
|
100
|
-
domain: 'localhost:3010',
|
|
101
|
-
url: 'http://localhost:3010',
|
|
90
|
+
profile: 'dev'
|
|
102
91
|
} : {
|
|
103
92
|
name: 'server',
|
|
104
93
|
profile: 'prod',
|
|
105
|
-
level: 'silly',
|
|
106
|
-
|
|
107
|
-
localIP: '86.76.176.80',
|
|
108
|
-
domain: 'megacharger.io',
|
|
109
|
-
url: 'https://megacharger.io',
|
|
110
94
|
}
|
|
111
95
|
}
|
|
112
96
|
|
package/src/server/app/index.ts
CHANGED
|
@@ -74,7 +74,7 @@ export class App {
|
|
|
74
74
|
get: (container, serviceId, receiver) => {
|
|
75
75
|
|
|
76
76
|
if (!( serviceId in container ) && typeof serviceId === 'string')
|
|
77
|
-
throw new Error(`
|
|
77
|
+
throw new Error(`The following service is required as a dependancy: ${serviceId}`);
|
|
78
78
|
|
|
79
79
|
return container[serviceId];
|
|
80
80
|
}
|
|
@@ -34,7 +34,7 @@ export default ({ page, children: html, request, ssrData }: {
|
|
|
34
34
|
|
|
35
35
|
const routesForClient = JSON.stringify( services.router.ssrRoutes );
|
|
36
36
|
|
|
37
|
-
const fullUrl = services.http.
|
|
37
|
+
const fullUrl = services.http.publicUrl + request.path;
|
|
38
38
|
|
|
39
39
|
let attrsBody = {
|
|
40
40
|
className: [...page.bodyClass].join(' '),
|
|
@@ -89,16 +89,22 @@ export default abstract class UserAuthBase {
|
|
|
89
89
|
public abstract beforeSignup(user: User): Promise< void >;
|
|
90
90
|
public abstract afterSignup(user: User): Promise<{ redirect: string }>;
|
|
91
91
|
|
|
92
|
-
private googleClient
|
|
93
|
-
? new OAuth2Client(
|
|
94
|
-
app.config.auth.google.web.clientId, // Google Client ID
|
|
95
|
-
app.config.auth.google.web.secret, // Private key
|
|
96
|
-
"https://" + app.env.domain + "/auth/google/response" // Redirect url
|
|
97
|
-
)
|
|
98
|
-
: undefined;
|
|
92
|
+
private googleClient: OAuth2Client | undefined;
|
|
99
93
|
|
|
100
94
|
public async load() {
|
|
101
95
|
|
|
96
|
+
// Google auth client
|
|
97
|
+
if (app.config.auth.google) {
|
|
98
|
+
|
|
99
|
+
const httpConfig = app.services.http.publicUrl;
|
|
100
|
+
|
|
101
|
+
this.googleClient = new OAuth2Client(
|
|
102
|
+
app.config.auth.google.web.clientId, // Google Client ID
|
|
103
|
+
app.config.auth.google.web.secret, // Private key
|
|
104
|
+
httpConfig + "/auth/google/response" // Redirect url
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
102
108
|
}
|
|
103
109
|
|
|
104
110
|
public async FromEmail(
|
|
@@ -145,7 +151,8 @@ export default abstract class UserAuthBase {
|
|
|
145
151
|
request: ServerRequest,
|
|
146
152
|
): Promise<AuthResponse> {
|
|
147
153
|
|
|
148
|
-
|
|
154
|
+
const googleConfig = app.config.auth.google;
|
|
155
|
+
if (!this.googleClient || !googleConfig)
|
|
149
156
|
throw new Forbidden(`Authentication method disabled.`);
|
|
150
157
|
|
|
151
158
|
if (codeOrToken === undefined)
|
|
@@ -156,15 +163,15 @@ export default abstract class UserAuthBase {
|
|
|
156
163
|
return this.GoogleResponse('token', r.tokens.id_token, request);
|
|
157
164
|
}
|
|
158
165
|
|
|
159
|
-
config.debug && console.log(LogPrefix, "Auth via google",
|
|
166
|
+
config.debug && console.log(LogPrefix, "Auth via google", googleConfig);
|
|
160
167
|
|
|
161
168
|
let ticket: LoginTicket;
|
|
162
169
|
try {
|
|
163
170
|
ticket = await this.googleClient.verifyIdToken({
|
|
164
171
|
idToken: codeOrToken,
|
|
165
172
|
audience: [
|
|
166
|
-
|
|
167
|
-
|
|
173
|
+
googleConfig.web.clientId,
|
|
174
|
+
googleConfig.android.clientId,
|
|
168
175
|
]
|
|
169
176
|
});
|
|
170
177
|
} catch (error) {
|
|
@@ -19,8 +19,15 @@ import BugReporter from "./bugReporter";
|
|
|
19
19
|
|
|
20
20
|
export type TReportTransport = keyof typeof $
|
|
21
21
|
|
|
22
|
+
type TLogProfile = 'silly' | 'info' | 'warn' | 'error'
|
|
23
|
+
|
|
22
24
|
export type ConsoleConfig = {
|
|
23
|
-
|
|
25
|
+
dev: {
|
|
26
|
+
level: TLogProfile,
|
|
27
|
+
},
|
|
28
|
+
prod: {
|
|
29
|
+
level: TLogProfile
|
|
30
|
+
}
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
declare global {
|
|
@@ -120,6 +127,8 @@ export class Console {
|
|
|
120
127
|
----------------------------------*/
|
|
121
128
|
public load() {
|
|
122
129
|
|
|
130
|
+
const envConfig = app.config.console[ app.env.profile ];
|
|
131
|
+
|
|
123
132
|
this.logger = new Logger({
|
|
124
133
|
overwriteConsole: true,
|
|
125
134
|
//type: app.env.profile === 'dev' ? 'pretty' : 'hidden',
|
|
@@ -138,7 +147,7 @@ export class Console {
|
|
|
138
147
|
warn: this.log.bind(this),
|
|
139
148
|
error: this.log.bind(this),
|
|
140
149
|
fatal: this.log.bind(this),
|
|
141
|
-
},
|
|
150
|
+
}, envConfig.level);
|
|
142
151
|
|
|
143
152
|
setInterval(() => this.clean(), 60000);
|
|
144
153
|
|
|
@@ -98,7 +98,7 @@ export default class Email {
|
|
|
98
98
|
to: config.bugReport.to,
|
|
99
99
|
subject: "Bug on server: " + (report.error.message),
|
|
100
100
|
html: `
|
|
101
|
-
<a href="${app.
|
|
101
|
+
<a href="${app.services.http.publicUrl}/admin/activity/requests/${report.channelId}">
|
|
102
102
|
View Request details & console
|
|
103
103
|
</a>
|
|
104
104
|
<br/>
|
|
@@ -11,9 +11,6 @@ import path from 'path';
|
|
|
11
11
|
import cors from 'cors';
|
|
12
12
|
//var serveStatic = require('serve-static')
|
|
13
13
|
|
|
14
|
-
// Npm: Autres
|
|
15
|
-
import fs from 'fs-extra';
|
|
16
|
-
|
|
17
14
|
// Middlewares (npm)
|
|
18
15
|
import morgan from 'morgan';
|
|
19
16
|
import hpp from 'hpp'; // Protection contre la pollution des reuqtees http
|
|
@@ -38,13 +35,18 @@ import { MiddlewareFormData } from './multipart';
|
|
|
38
35
|
----------------------------------*/
|
|
39
36
|
|
|
40
37
|
export type HttpServiceConfig = {
|
|
41
|
-
port: number
|
|
42
|
-
ssl: boolean,
|
|
43
38
|
|
|
39
|
+
// Access
|
|
40
|
+
domain: string,
|
|
41
|
+
port: number,
|
|
42
|
+
ssl: number,
|
|
43
|
+
|
|
44
|
+
// Limitations / Load restriction
|
|
44
45
|
upload: {
|
|
45
46
|
maxSize: string // Expression package bytes
|
|
46
47
|
},
|
|
47
48
|
|
|
49
|
+
// Protections against bots
|
|
48
50
|
security: {
|
|
49
51
|
recaptcha: {
|
|
50
52
|
prv: string,
|
|
@@ -75,35 +77,19 @@ export default class HttpServer {
|
|
|
75
77
|
public router: Router;
|
|
76
78
|
|
|
77
79
|
public config: HttpServiceConfig;
|
|
78
|
-
public
|
|
80
|
+
public publicUrl: string;
|
|
79
81
|
|
|
80
82
|
public constructor() {
|
|
81
83
|
|
|
82
84
|
// Init
|
|
83
85
|
this.config = app.config.http;
|
|
84
|
-
this.
|
|
85
|
-
|
|
86
|
+
this.publicUrl = app.env.name === 'local'
|
|
87
|
+
? 'http://localhost:' + this.config.port
|
|
88
|
+
: ((this.config.ssl ? 'https' : 'http') + '://' + this.config.domain);
|
|
86
89
|
|
|
87
90
|
// Configure HTTP server
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this.http = http.createServer(this.express);
|
|
91
|
-
|
|
92
|
-
} /*else if ('ssh' in app.env) {
|
|
93
|
-
|
|
94
|
-
const ssh = app.env.ssh;
|
|
95
|
-
|
|
96
|
-
console.log("Création du serveur https pour le socket:", '/home/' + ssh.login + '/ssl.*');
|
|
97
|
-
this.http = https.createServer({
|
|
98
|
-
key: fs.readFileSync('/home/' + ssh.login + '/ssl.key'),
|
|
99
|
-
cert: fs.readFileSync('/home/' + ssh.login + '/ssl.cert'),
|
|
100
|
-
ca: fs.readFileSync('/home/' + ssh.login + '/ssl.ca'),
|
|
101
|
-
requestCert: true,
|
|
102
|
-
rejectUnauthorized: false
|
|
103
|
-
}, this.express);
|
|
104
|
-
|
|
105
|
-
}*/ else
|
|
106
|
-
throw new Error(`SSL was enabled, but no ssh config was specified in app.env (required to load ssl certificate files)`);
|
|
91
|
+
this.express = express();
|
|
92
|
+
this.http = http.createServer(this.express);
|
|
107
93
|
|
|
108
94
|
// Start HTTP Server
|
|
109
95
|
this.router = app.services.router;
|
|
@@ -248,7 +234,7 @@ export default class HttpServer {
|
|
|
248
234
|
// Impossible donc de créer un serveur http ici, on le fera dans start.js
|
|
249
235
|
console.info("Lancement du serveur web");
|
|
250
236
|
this.http.listen(this.config.port, () => {
|
|
251
|
-
console.info(`Serveur web démarré sur
|
|
237
|
+
console.info(`Serveur web démarré sur ${this.publicUrl}`);
|
|
252
238
|
});
|
|
253
239
|
|
|
254
240
|
}
|