Skip to content

Commit 0b1710e

Browse files
author
Stanislav V Vyaliy
committed
ssl port
1 parent ea08f83 commit 0b1710e

35 files changed

+456
-320
lines changed

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# App
22
PORT=4000
3+
PORT_SSL=4443
34

45
# DB
56
DATABASE_URI="postgres://postgres:[email protected]:5432/postgres"

.eslintignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.git
22
.local
33
.vscode
4-
apps/portal/src/database/migrations
54
dist
5+
secure
66

77
# Logs
88
logs

.gitlab-ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ helm_development:
119119
--set service.nodePort="30400" \
120120
--set service.nodePort_debug="30401" \
121121
--set PORT="${PORT}" \
122+
--set PORT_SSL="${PORT_SSL}" \
122123
--set DATABASE_URI="${DATABASE_URI}" \
123124
--set DATABASE_URI_RD="${DATABASE_URI_RD}" \
124125
--set DATABASE_SCHEMA="${DATABASE_SCHEMA}" \
@@ -188,6 +189,7 @@ helm_production:
188189
--set service.nodePort="30300" \
189190
--set service.nodePort_debug="30301" \
190191
--set PORT="${PORT}" \
192+
--set PORT_SSL="${PORT_SSL}" \
191193
--set DATABASE_URI="${DATABASE_URI}" \
192194
--set DATABASE_URI_RD="${DATABASE_URI_RD}" \
193195
--set DATABASE_SCHEMA="${DATABASE_SCHEMA}" \

Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ ENV NODE_ENV ${NODE_ENV}
1111

1212
ARG PORT=4000
1313
ENV PORT ${PORT}
14+
ARG PORT_SSL=4443
15+
ENV PORT_SSL ${PORT_SSL}
1416

1517
# Database
1618
ARG DATABASE_URI=postgres://postgres:1234567890@localhost:5432/portaldb
@@ -128,7 +130,7 @@ RUN dpkg-reconfigure -f noninteractive tzdata
128130
COPY . ./
129131

130132
# EXPOSE
131-
EXPOSE ${PORT}
133+
EXPOSE ${PORT} ${PORT_SSL}
132134

133135
# YARN START
134136
ENTRYPOINT [ "./entrypoint.sh" ]

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ The `.env` file is like this:
135135
```bash
136136
# App
137137
PORT=4000
138+
PORT_SSL=4443
138139

139140
# DB
140141
DATABASE_URI="postgres://postgres:[email protected]:5432/postgres"

apps/portal/__tests__/index.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React from 'react';
77

88
import App from '@front/pages';
99

10-
describe('App', () => {
10+
describe('Next.JS Front App', () => {
1111
let shallow: typeof Shallow;
1212
const props = {
1313
namespacesRequired: [],

apps/portal/components/auth/login.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export const LoginComponent: FC<LoginComponentProps> = ({
107107
<Typography className={classes.title} variant="h4">
108108
{t('common:authorization')}
109109
</Typography>
110-
<Tooltip title={t('login:tooltip')} placement="top" leaveDelay={3000}>
110+
<Tooltip title={t('login:tooltip') || ''} placement="top" leaveDelay={3000}>
111111
<FormControl className={classes.formControl} fullWidth variant="outlined">
112112
<TextField
113113
inputRef={usernameRef}
File renamed without changes.

apps/portal/components/drawer.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const DrawerComponent: FC<DrawerProps> = ({ open, isMobile, handleOpen }) => {
148148
.map((url) => (
149149
<li key={url.link}>
150150
<Link href={url.link} passHref>
151-
<Tooltip title={t(url.text)} enterDelay={1000}>
151+
<Tooltip title={t(url.text) || ''} enterDelay={1000}>
152152
<ListItem
153153
button
154154
selected={pathname.startsWith(url.link)}
File renamed without changes.

apps/portal/lib/types/auth.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,24 @@ export interface LoginValuesProps {
2929
password: string;
3030
}
3131

32-
// #region Email Session Props
33-
export interface MailSession {
32+
// #region Email session
33+
export interface EmailSession {
3434
error?: string;
3535
sessid?: string;
3636
sessauth?: string;
3737
}
3838
// #endregion
3939

40-
// #region User response
41-
export interface UserSession {
42-
user: User;
43-
mailSession?: MailSession;
44-
passwordFrontend?: string;
40+
// #region Login email
41+
export interface LoginEmail {
42+
login: boolean;
43+
error?: string;
44+
}
45+
// #endregion
46+
47+
// #region Login response
48+
export interface Login {
49+
login: boolean;
50+
email: LoginEmail;
4551
}
4652
// #endregion

apps/portal/lib/with-apollo-client.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { onError } from 'apollo-link-error';
1111
import { setContext } from 'apollo-link-context';
1212
import { createHttpLink } from 'apollo-link-http';
1313
import { createUploadLink } from 'apollo-upload-client';
14-
import fetch from 'isomorphic-fetch';
1514
import { InMemoryCache, NormalizedCacheObject } from 'apollo-cache-inmemory';
1615
// import { InStorageCache } from 'apollo-cache-instorage';
1716
// import { PersistentStorage, PersistedData } from 'apollo-cache-persist/types';
@@ -68,6 +67,9 @@ const createClient = ({ initialState, cookie }: CreateClientProps): ApolloClient
6867
let cache: InMemoryCache;
6968

7069
if (__SERVER__) {
70+
// eslint-disable-next-line global-require
71+
const fetch = require('node-fetch');
72+
7173
global.fetch = fetch;
7274

7375
httpLink = createHttpLink({

apps/portal/next.config.js

+1-23
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,6 @@ function withCustomWebpack(conf = {}) {
4040
__SERVER__: JSON.stringify(isServer),
4141
}),
4242
new DotenvWebpackPlugin({ path: resolve(__dirname, '../../.env') }),
43-
// new Webpack.IgnorePlugin({
44-
// checkResource(resource) {
45-
// const lazyImports = [
46-
// // '@nestjs/microservices',
47-
// // '@nestjs/platform-express',
48-
// // 'class-validator',
49-
// // 'class-transformer',
50-
// // 'google-libphonenumber',
51-
// // 'cache-manager',
52-
// ];
53-
// if (!lazyImports.includes(resource)) {
54-
// return false;
55-
// }
56-
// try {
57-
// require.resolve(resource);
58-
// } catch (err) {
59-
// return true;
60-
// }
61-
// return false;
62-
// },
63-
// }),
6443
];
6544

6645
if (!isServer && !dev) {
@@ -117,7 +96,6 @@ function withCustomWebpack(conf = {}) {
11796
// debugger;
11897

11998
// config.externals = [...(config.externals || []), nodeExternals()];
120-
12199
// console.log(isServer ? 'Server' : 'Client', config);
122100

123101
return webpack(config, { isServer, ...rest });
@@ -137,7 +115,7 @@ const plugins = [
137115
imagesName: '[name]-[hash].[ext]',
138116
handleImages: ['jpeg', 'png', 'svg', 'webp', 'gif'],
139117
optimizeImages: true,
140-
optimizeImagesInDev: true,
118+
optimizeImagesInDev: false,
141119
mozjpeg: {
142120
quality: 80,
143121
},

apps/portal/pages/auth/login.tsx

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
// #region Imports NPM
44
import React, { useRef, useState, useEffect } from 'react';
55
import Head from 'next/head';
6-
import { useApolloClient, useLazyQuery } from '@apollo/react-hooks';
6+
import { useLazyQuery } from '@apollo/react-hooks';
77
import queryString from 'query-string';
88
import Router from 'next/router';
99
// #endregion
1010
// #region Imports Local
11-
import { Data, LoginValuesProps, LoginPageProps } from '@lib/types';
12-
// import { setStorage, removeStorage } from '@lib/session-storage';
11+
import { Data, LoginValuesProps, LoginPageProps, Login } from '@lib/types';
1312
import { FIRST_PAGE } from '@lib/constants';
14-
import { User } from '@lib/types/user.dto';
1513
import { I18nPage, includeDefaultNamespaces, nextI18next } from '@lib/i18n-client';
1614
import Cookie from '@lib/cookie';
1715
import { LOGIN } from '@lib/queries';
@@ -20,8 +18,6 @@ import { LoginComponent } from '@front/components/auth/login';
2018
// #endregion
2119

2220
const AuthLoginPage: I18nPage<LoginPageProps> = ({ t, initUsername }): React.ReactElement => {
23-
const client = useApolloClient();
24-
2521
const usernameRef = useRef<HTMLInputElement>(null);
2622
const passwordRef = useRef<HTMLInputElement>(null);
2723

@@ -31,13 +27,13 @@ const AuthLoginPage: I18nPage<LoginPageProps> = ({ t, initUsername }): React.Rea
3127
password: '',
3228
});
3329

34-
const [login, { loading, error }] = useLazyQuery<Data<'login', boolean>, { username: string; password: string }>(
30+
const [login, { loading, error }] = useLazyQuery<Data<'login', Login>, { username: string; password: string }>(
3531
LOGIN,
3632
{
33+
ssr: false,
34+
fetchPolicy: 'no-cache',
3735
onCompleted: (data) => {
3836
if (data.login) {
39-
client.resetStore();
40-
4137
const { redirect = FIRST_PAGE } = queryString.parse(window.location.search);
4238
Router.push(redirect as string);
4339
}

apps/portal/src/auth/auth.graphql

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
type LoginEmail {
2+
login: Boolean!
3+
error: String
4+
}
5+
6+
type Login {
7+
login: Boolean
8+
email: LoginEmail
9+
}
10+
111
type Query {
212
me: User!
3-
login(username: String!, password: String!): Boolean!
4-
loginEmail: Boolean!
13+
login(username: String!, password: String!): Login!
14+
loginEmail: LoginEmail!
515
}
616

717
type Mutation {

apps/portal/src/auth/auth.resolver.ts

+25-76
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Request, Response } from 'express';
77
import { I18nService } from 'nestjs-i18n';
88
// #endregion
99
// #region Imports Local
10+
import { Login, LoginEmail } from '@lib/types/auth';
1011
import { User } from '@lib/types/user.dto';
1112
import { LogService } from '@app/logger';
1213
import { ConfigService } from '@app/config';
@@ -45,7 +46,7 @@ export class AuthResolver {
4546
* @method login
4647
* @param {string} username Username
4748
* @param {string} password Password
48-
* @returns {boolean} True if a login successfull
49+
* @returns {Login} The login response
4950
* @throws {GraphQLError}
5051
*/
5152
@Query()
@@ -54,7 +55,9 @@ export class AuthResolver {
5455
@Args('password') password: string,
5556
@Context('req') req: Request,
5657
@Context('res') res: Response,
57-
): Promise<boolean> {
58+
): Promise<Login> {
59+
let email: LoginEmail = { login: false };
60+
5861
const user = await this.authService
5962
.login({ username: username.toLowerCase(), password })
6063
.catch(async (error: Error) => {
@@ -70,44 +73,19 @@ export class AuthResolver {
7073
});
7174

7275
if (user.profile.email) {
73-
await this.authService
74-
.loginEmail(user.profile.email, password)
75-
.then(
76-
(response) => {
77-
const { sessid, sessauth } = response.data;
78-
if (sessid && sessauth) {
79-
const options = {
80-
// domain: '.portal.i-npz.ru',
81-
maxAge: this.configService.get<number>('SESSION_COOKIE_TTL'),
82-
};
83-
84-
res.cookie('roundcube_sessid', sessid, options);
85-
res.cookie('roundcube_sessauth', sessauth, options);
86-
87-
req!.session!.mailSession = {
88-
sessid,
89-
sessauth,
90-
};
91-
92-
return true;
93-
}
94-
95-
throw new Error('Undefined mailSession error.');
96-
},
97-
() => {
98-
return false;
99-
},
100-
)
101-
.catch((error: Error) => {
102-
this.logService.error('Unable to login in mail', error, AuthResolver.name);
103-
104-
return false;
105-
});
76+
email = await this.authService.loginEmail(user.profile.email, password, req, res).catch((error: Error) => {
77+
this.logService.error('Unable to login in mail', error, AuthResolver.name);
78+
79+
return {
80+
login: false,
81+
error: error.toString(),
82+
};
83+
});
10684
}
10785

10886
req!.session!.password = password;
10987

110-
return true;
88+
return { login: true, email };
11189
}
11290

11391
/**
@@ -120,48 +98,19 @@ export class AuthResolver {
12098
*/
12199
@Query()
122100
async loginEmail(
123-
@CurrentUser() user: User,
124-
@PasswordFrontend() password: string,
125101
@Context('req') req: Request,
126102
@Context('res') res: Response,
127-
): Promise<boolean> {
128-
if (user.profile.email) {
129-
return this.authService
130-
.loginEmail(user.profile.email, password)
131-
.then(
132-
(response) => {
133-
const { sessid, sessauth } = response.data;
134-
if (sessid && sessauth) {
135-
const options = {
136-
// domain: '.portal.i-npz.ru',
137-
maxAge: this.configService.get<number>('SESSION_COOKIE_TTL'),
138-
};
139-
140-
res.cookie('roundcube_sessid', sessid, options);
141-
res.cookie('roundcube_sessauth', sessauth, options);
142-
143-
req!.session!.mailSession = {
144-
sessid,
145-
sessauth,
146-
};
147-
148-
return true;
149-
}
150-
151-
throw new Error('Undefined mailSession error.');
152-
},
153-
() => {
154-
return false;
155-
},
156-
)
157-
.catch((error: Error) => {
158-
this.logService.error('Unable to login in mail', error, AuthResolver.name);
159-
160-
return false;
161-
});
162-
}
163-
164-
return false;
103+
@CurrentUser() user?: User,
104+
@PasswordFrontend() password?: string,
105+
): Promise<LoginEmail> {
106+
return this.authService.loginEmail(user?.profile.email || '', password || '', req, res).catch((error: Error) => {
107+
this.logService.error('Unable to login in mail', error, AuthResolver.name);
108+
109+
return {
110+
login: false,
111+
error: error.toString(),
112+
};
113+
});
165114
}
166115

167116
/**

0 commit comments

Comments
 (0)