express-generator-typescript 1.8.9 → 1.9.2
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/README.md +1 -1
- package/lib/auth-proj/.eslintignore +1 -0
- package/lib/auth-proj/.eslintrc.json +35 -0
- package/lib/auth-proj/package-lock.json +6770 -0
- package/lib/auth-proj/package.json +1 -35
- package/lib/auth-proj/src/index.ts +5 -5
- package/lib/auth-proj/src/pre-start/env/development.env +1 -1
- package/lib/auth-proj/src/repos/mock-orm.ts +13 -3
- package/lib/auth-proj/src/routes/auth-router.ts +1 -1
- package/lib/auth-proj/src/routes/middleware.ts +12 -6
- package/lib/auth-proj/src/routes/user-router.ts +2 -2
- package/lib/auth-proj/src/server.ts +2 -2
- package/lib/auth-proj/src/shared/env-vars.ts +6 -6
- package/lib/auth-proj/src/shared/functions.ts +2 -2
- package/lib/auth-proj/src/types/express/index.d.ts +22 -0
- package/lib/express-generator-typescript.js +2 -2
- package/lib/project-files/.eslintignore +1 -0
- package/lib/project-files/.eslintrc.json +35 -0
- package/lib/project-files/package.json +1 -35
- package/lib/project-files/src/index.ts +5 -4
- package/lib/project-files/src/routes/user-router.ts +1 -1
- package/lib/project-files/src/server.ts +5 -4
- package/lib/project-files/src/shared/env-vars.ts +4 -0
- package/lib/socket-io/.eslintignore +1 -0
- package/lib/socket-io/.eslintrc.json +35 -0
- package/lib/socket-io/package.json +1 -75
- package/lib/socket-io/src/index.ts +5 -4
- package/lib/socket-io/src/routes/auth-router.ts +1 -1
- package/lib/socket-io/src/routes/chat-router.ts +1 -1
- package/lib/socket-io/src/routes/user-router.ts +1 -1
- package/lib/socket-io/src/shared/env-vars.ts +6 -6
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"build": "npx ts-node build.ts",
|
|
6
6
|
"lint": "eslint . --ext .ts",
|
|
7
7
|
"start": "node -r module-alias/register ./dist --env=production",
|
|
8
|
-
"
|
|
8
|
+
"dev": "nodemon",
|
|
9
9
|
"test": "nodemon --config ./spec/nodemon.json",
|
|
10
10
|
"test:no-reloading": "npx ts-node --files -r tsconfig-paths/register ./spec"
|
|
11
11
|
},
|
|
@@ -28,40 +28,6 @@
|
|
|
28
28
|
"@routes": "dist/routes",
|
|
29
29
|
"@util": "dist/util"
|
|
30
30
|
},
|
|
31
|
-
"eslintConfig": {
|
|
32
|
-
"parser": "@typescript-eslint/parser",
|
|
33
|
-
"plugins": [
|
|
34
|
-
"@typescript-eslint"
|
|
35
|
-
],
|
|
36
|
-
"extends": [
|
|
37
|
-
"eslint:recommended",
|
|
38
|
-
"plugin:@typescript-eslint/recommended",
|
|
39
|
-
"plugin:@typescript-eslint/recommended-requiring-type-checking"
|
|
40
|
-
],
|
|
41
|
-
"parserOptions": {
|
|
42
|
-
"project": "./tsconfig.json"
|
|
43
|
-
},
|
|
44
|
-
"rules": {
|
|
45
|
-
"max-len": [
|
|
46
|
-
"error",
|
|
47
|
-
{
|
|
48
|
-
"code": 100
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
"no-console": 1,
|
|
52
|
-
"no-extra-boolean-cast": 0,
|
|
53
|
-
"@typescript-eslint/restrict-plus-operands": 0,
|
|
54
|
-
"@typescript-eslint/explicit-module-boundary-types": 0,
|
|
55
|
-
"@typescript-eslint/no-explicit-any": 0,
|
|
56
|
-
"@typescript-eslint/no-floating-promises": 0,
|
|
57
|
-
"@typescript-eslint/no-unsafe-member-access": 0,
|
|
58
|
-
"@typescript-eslint/no-unsafe-assignment": 0
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
"eslintIgnore": [
|
|
62
|
-
"src/public/",
|
|
63
|
-
"build.ts"
|
|
64
|
-
],
|
|
65
31
|
"dependencies": {
|
|
66
32
|
},
|
|
67
33
|
"devDependencies": {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import './pre-start'; // Must be the first import
|
|
2
|
-
import envVars from './shared/env-vars';
|
|
3
2
|
import logger from 'jet-logger';
|
|
3
|
+
|
|
4
|
+
import envVars from '@shared/env-vars';
|
|
4
5
|
import server from './server';
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
// Constants
|
|
8
|
-
const serverStartMsg = 'Express server started on port: '
|
|
9
|
-
port = (envVars.port || 3000);
|
|
9
|
+
const serverStartMsg = 'Express server started on port: ';
|
|
10
10
|
|
|
11
11
|
// Start server
|
|
12
|
-
server.listen(port, () => {
|
|
13
|
-
logger.info(serverStartMsg + port);
|
|
12
|
+
server.listen(envVars.port, () => {
|
|
13
|
+
logger.info(serverStartMsg + envVars.port.toString());
|
|
14
14
|
});
|
|
@@ -1,24 +1,34 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
2
|
+
|
|
1
3
|
import jsonfile from 'jsonfile';
|
|
4
|
+
import { IUser } from '@models/user-model';
|
|
2
5
|
|
|
3
6
|
|
|
4
|
-
// ****
|
|
7
|
+
// **** Variables **** //
|
|
5
8
|
|
|
6
9
|
const dbFilePath = 'src/repos/database.json';
|
|
7
10
|
|
|
8
11
|
|
|
12
|
+
// **** Types **** //
|
|
13
|
+
|
|
14
|
+
interface IDb {
|
|
15
|
+
users: IUser[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
9
19
|
// **** Functions **** //
|
|
10
20
|
|
|
11
21
|
/**
|
|
12
22
|
* Fetch the json from the file.
|
|
13
23
|
*/
|
|
14
|
-
function openDb(): Promise<
|
|
24
|
+
function openDb(): Promise<IDb> {
|
|
15
25
|
return jsonfile.readFile(dbFilePath);
|
|
16
26
|
}
|
|
17
27
|
|
|
18
28
|
/**
|
|
19
29
|
* Update the file.
|
|
20
30
|
*/
|
|
21
|
-
function saveDb(db:
|
|
31
|
+
function saveDb(db: IDb): Promise<void> {
|
|
22
32
|
return jsonfile.writeFile(dbFilePath, db);
|
|
23
33
|
}
|
|
24
34
|
|
|
@@ -27,7 +27,7 @@ export const p = {
|
|
|
27
27
|
router.post(p.login, async (req: Request, res: Response) => {
|
|
28
28
|
// Check email and password present
|
|
29
29
|
const { email, password } = req.body;
|
|
30
|
-
if (!
|
|
30
|
+
if (!email || !password) {
|
|
31
31
|
throw new ParamMissingError();
|
|
32
32
|
}
|
|
33
33
|
// Get jwt
|
|
@@ -18,8 +18,9 @@ const jwtNotPresentErr = 'JWT not present in signed cookie.';
|
|
|
18
18
|
* Middleware to verify if user is an admin.
|
|
19
19
|
*/
|
|
20
20
|
export async function adminMw(req: Request, res: Response, next: NextFunction) {
|
|
21
|
+
// Try
|
|
21
22
|
try {
|
|
22
|
-
//
|
|
23
|
+
// Extract the token
|
|
23
24
|
const jwt = req.signedCookies[envVars.cookieProps.key];
|
|
24
25
|
if (!jwt) {
|
|
25
26
|
throw Error(jwtNotPresentErr);
|
|
@@ -32,9 +33,14 @@ export async function adminMw(req: Request, res: Response, next: NextFunction) {
|
|
|
32
33
|
} else {
|
|
33
34
|
throw Error(jwtNotPresentErr);
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
// Catch
|
|
37
|
+
} catch (err: unknown) {
|
|
38
|
+
let error;
|
|
39
|
+
if (typeof err === 'string') {
|
|
40
|
+
error = err;
|
|
41
|
+
} else if (err instanceof Error) {
|
|
42
|
+
error = err.message;
|
|
43
|
+
}
|
|
44
|
+
return res.status(UNAUTHORIZED).json({ error });
|
|
39
45
|
}
|
|
40
|
-
}
|
|
46
|
+
}
|
|
@@ -20,14 +20,14 @@ export const p = {
|
|
|
20
20
|
} as const;
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
// ****
|
|
23
|
+
// **** Routes **** //
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Get all users.
|
|
27
27
|
*/
|
|
28
28
|
router.get(p.get, async (_: Request, res: Response) => {
|
|
29
29
|
const users = await userService.getAll();
|
|
30
|
-
return res.status(OK).json({users});
|
|
30
|
+
return res.status(OK).json({ users });
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
/**
|
|
@@ -3,7 +3,7 @@ import morgan from 'morgan';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import helmet from 'helmet';
|
|
5
5
|
import StatusCodes from 'http-status-codes';
|
|
6
|
-
import express, {
|
|
6
|
+
import express, { Request, Response } from 'express';
|
|
7
7
|
|
|
8
8
|
import 'express-async-errors';
|
|
9
9
|
|
|
@@ -41,7 +41,7 @@ if (envVars.nodeEnv === 'production') {
|
|
|
41
41
|
app.use('/api', BaseRouter);
|
|
42
42
|
|
|
43
43
|
// Error handling
|
|
44
|
-
app.use((err: Error | CustomError, _: Request, res: Response
|
|
44
|
+
app.use((err: Error | CustomError, _: Request, res: Response) => {
|
|
45
45
|
logger.err(err, true);
|
|
46
46
|
const status = (err instanceof CustomError ? err.HttpStatus : StatusCodes.BAD_REQUEST);
|
|
47
47
|
return res.status(status).json({
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
nodeEnv: process.env.NODE_ENV ?? '',
|
|
3
|
-
port: process.env.PORT ?? 0,
|
|
2
|
+
nodeEnv: (process.env.NODE_ENV ?? ''),
|
|
3
|
+
port: (process.env.PORT ?? 0),
|
|
4
4
|
cookieProps: {
|
|
5
5
|
key: 'ExpressGeneratorTs',
|
|
6
|
-
secret: process.env.COOKIE_SECRET ?? '',
|
|
6
|
+
secret: (process.env.COOKIE_SECRET ?? ''),
|
|
7
7
|
options: {
|
|
8
8
|
httpOnly: true,
|
|
9
9
|
signed: true,
|
|
@@ -14,7 +14,7 @@ export default {
|
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
16
|
jwt: {
|
|
17
|
-
secret: process.env.JWT_SECRET ?? '',
|
|
18
|
-
exp: process.env.COOKIE_EXP ?? '', // exp at the same time as the cookie
|
|
17
|
+
secret: (process.env.JWT_SECRET ?? ''),
|
|
18
|
+
exp: (process.env.COOKIE_EXP ?? ''), // exp at the same time as the cookie
|
|
19
19
|
},
|
|
20
|
-
};
|
|
20
|
+
} as const;
|
|
@@ -8,11 +8,11 @@ export function pErr(err?: Error): void {
|
|
|
8
8
|
if (!!err) {
|
|
9
9
|
logger.err(err);
|
|
10
10
|
}
|
|
11
|
-
}
|
|
11
|
+
}
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Get a random number between 1 and 1,000,000,000,000
|
|
15
15
|
*/
|
|
16
16
|
export function getRandomInt(): number {
|
|
17
17
|
return Math.floor(Math.random() * 1_000_000_000_000);
|
|
18
|
-
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IUser } from "@models/user-model";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
declare module 'express' {
|
|
5
|
+
export interface Request {
|
|
6
|
+
signedCookies: Record<string, string>,
|
|
7
|
+
body: {
|
|
8
|
+
user?: IUser
|
|
9
|
+
email?: string;
|
|
10
|
+
password?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Put this back in the future for middleware stuff
|
|
16
|
+
// declare global {
|
|
17
|
+
// namespace Express {
|
|
18
|
+
// export interface Response {
|
|
19
|
+
// sessionUser: IClientData;
|
|
20
|
+
// }
|
|
21
|
+
// }
|
|
22
|
+
// }
|
|
@@ -10,7 +10,6 @@ const childProcess = require('child_process');
|
|
|
10
10
|
const ncp = require('ncp').ncp;
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
/**
|
|
15
14
|
* Entry point
|
|
16
15
|
*/
|
|
@@ -102,5 +101,6 @@ function downloadNodeModules(destination, depStrings, useYarn) {
|
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
|
|
105
|
-
// Export entry point
|
|
104
|
+
// **** Export entry point **** //
|
|
105
|
+
|
|
106
106
|
module.exports = expressGenTs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
src/public/
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parser": "@typescript-eslint/parser",
|
|
3
|
+
"plugins": [
|
|
4
|
+
"@typescript-eslint"
|
|
5
|
+
],
|
|
6
|
+
"extends": [
|
|
7
|
+
"eslint:recommended",
|
|
8
|
+
"plugin:@typescript-eslint/recommended",
|
|
9
|
+
"plugin:@typescript-eslint/recommended-requiring-type-checking"
|
|
10
|
+
],
|
|
11
|
+
"parserOptions": {
|
|
12
|
+
"project": "./tsconfig.json"
|
|
13
|
+
},
|
|
14
|
+
"rules": {
|
|
15
|
+
"max-len": [
|
|
16
|
+
"error",
|
|
17
|
+
{
|
|
18
|
+
"code": 100
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"no-console": 1,
|
|
22
|
+
"no-extra-boolean-cast": 0,
|
|
23
|
+
"semi": 1,
|
|
24
|
+
"@typescript-eslint/restrict-plus-operands": 0,
|
|
25
|
+
"@typescript-eslint/explicit-module-boundary-types": 0,
|
|
26
|
+
"@typescript-eslint/no-explicit-any": 0,
|
|
27
|
+
"@typescript-eslint/no-floating-promises": 0,
|
|
28
|
+
"@typescript-eslint/no-unsafe-member-access": 0,
|
|
29
|
+
"@typescript-eslint/no-unsafe-assignment": 0,
|
|
30
|
+
"@typescript-eslint/no-misused-promises": 0,
|
|
31
|
+
"@typescript-eslint/no-unsafe-argument": 0,
|
|
32
|
+
"@typescript-eslint/no-unsafe-return": 0,
|
|
33
|
+
"@typescript-eslint/no-unsafe-call": 0
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"build": "npx ts-node build.ts",
|
|
6
6
|
"lint": "eslint . --ext .ts",
|
|
7
7
|
"start": "node -r module-alias/register ./dist --env=production",
|
|
8
|
-
"
|
|
8
|
+
"dev": "nodemon",
|
|
9
9
|
"test": "nodemon --config ./spec/nodemon.json",
|
|
10
10
|
"test:no-reloading": "npx ts-node -r tsconfig-paths/register ./spec"
|
|
11
11
|
},
|
|
@@ -27,40 +27,6 @@
|
|
|
27
27
|
"@server": "dist/server",
|
|
28
28
|
"@routes": "dist/routes"
|
|
29
29
|
},
|
|
30
|
-
"eslintConfig": {
|
|
31
|
-
"parser": "@typescript-eslint/parser",
|
|
32
|
-
"plugins": [
|
|
33
|
-
"@typescript-eslint"
|
|
34
|
-
],
|
|
35
|
-
"extends": [
|
|
36
|
-
"eslint:recommended",
|
|
37
|
-
"plugin:@typescript-eslint/recommended",
|
|
38
|
-
"plugin:@typescript-eslint/recommended-requiring-type-checking"
|
|
39
|
-
],
|
|
40
|
-
"parserOptions": {
|
|
41
|
-
"project": "./tsconfig.json"
|
|
42
|
-
},
|
|
43
|
-
"rules": {
|
|
44
|
-
"max-len": [
|
|
45
|
-
"error",
|
|
46
|
-
{
|
|
47
|
-
"code": 100
|
|
48
|
-
}
|
|
49
|
-
],
|
|
50
|
-
"no-console": 1,
|
|
51
|
-
"no-extra-boolean-cast": 0,
|
|
52
|
-
"@typescript-eslint/restrict-plus-operands": 0,
|
|
53
|
-
"@typescript-eslint/explicit-module-boundary-types": 0,
|
|
54
|
-
"@typescript-eslint/no-explicit-any": 0,
|
|
55
|
-
"@typescript-eslint/no-floating-promises": 0,
|
|
56
|
-
"@typescript-eslint/no-unsafe-member-access": 0,
|
|
57
|
-
"@typescript-eslint/no-unsafe-assignment": 0
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
"eslintIgnore": [
|
|
61
|
-
"src/public/",
|
|
62
|
-
"build.ts"
|
|
63
|
-
],
|
|
64
30
|
"dependencies": {
|
|
65
31
|
},
|
|
66
32
|
"devDependencies": {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import './pre-start'; // Must be the first import
|
|
2
2
|
import logger from 'jet-logger';
|
|
3
|
+
|
|
4
|
+
import envVars from '@shared/env-vars';
|
|
3
5
|
import server from './server';
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
// Constants
|
|
7
|
-
const serverStartMsg = 'Express server started on port: '
|
|
8
|
-
port = (process.env.PORT || 3000);
|
|
9
|
+
const serverStartMsg = 'Express server started on port: ';
|
|
9
10
|
|
|
10
11
|
// Start server
|
|
11
|
-
server.listen(port, () => {
|
|
12
|
-
logger.info(serverStartMsg + port);
|
|
12
|
+
server.listen(envVars.port, () => {
|
|
13
|
+
logger.info(serverStartMsg + envVars.port);
|
|
13
14
|
});
|
|
@@ -2,13 +2,14 @@ import cookieParser from 'cookie-parser';
|
|
|
2
2
|
import morgan from 'morgan';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import helmet from 'helmet';
|
|
5
|
+
import logger from 'jet-logger';
|
|
5
6
|
|
|
6
7
|
import express, { NextFunction, Request, Response } from 'express';
|
|
7
8
|
import StatusCodes from 'http-status-codes';
|
|
8
9
|
import 'express-async-errors';
|
|
9
10
|
|
|
10
|
-
import apiRouter from '
|
|
11
|
-
import
|
|
11
|
+
import apiRouter from '@routes/api';
|
|
12
|
+
import envVars from '@shared/env-vars';
|
|
12
13
|
import { CustomError } from '@shared/errors';
|
|
13
14
|
|
|
14
15
|
|
|
@@ -25,12 +26,12 @@ app.use(express.urlencoded({extended: true}));
|
|
|
25
26
|
app.use(cookieParser());
|
|
26
27
|
|
|
27
28
|
// Show routes called in console during development
|
|
28
|
-
if (
|
|
29
|
+
if (envVars.nodeEnv === 'development') {
|
|
29
30
|
app.use(morgan('dev'));
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
// Security (helmet recommended in express docs)
|
|
33
|
-
if (
|
|
34
|
+
if (envVars.nodeEnv === 'production') {
|
|
34
35
|
app.use(helmet());
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
src/public/
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parser": "@typescript-eslint/parser",
|
|
3
|
+
"plugins": [
|
|
4
|
+
"@typescript-eslint"
|
|
5
|
+
],
|
|
6
|
+
"extends": [
|
|
7
|
+
"eslint:recommended",
|
|
8
|
+
"plugin:@typescript-eslint/recommended",
|
|
9
|
+
"plugin:@typescript-eslint/recommended-requiring-type-checking"
|
|
10
|
+
],
|
|
11
|
+
"parserOptions": {
|
|
12
|
+
"project": "./tsconfig.json"
|
|
13
|
+
},
|
|
14
|
+
"rules": {
|
|
15
|
+
"max-len": [
|
|
16
|
+
"error",
|
|
17
|
+
{
|
|
18
|
+
"code": 100
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"no-console": 1,
|
|
22
|
+
"no-extra-boolean-cast": 0,
|
|
23
|
+
"semi": 1,
|
|
24
|
+
"@typescript-eslint/restrict-plus-operands": 0,
|
|
25
|
+
"@typescript-eslint/explicit-module-boundary-types": 0,
|
|
26
|
+
"@typescript-eslint/no-explicit-any": 0,
|
|
27
|
+
"@typescript-eslint/no-floating-promises": 0,
|
|
28
|
+
"@typescript-eslint/no-unsafe-member-access": 0,
|
|
29
|
+
"@typescript-eslint/no-unsafe-assignment": 0,
|
|
30
|
+
"@typescript-eslint/no-misused-promises": 0,
|
|
31
|
+
"@typescript-eslint/no-unsafe-argument": 0,
|
|
32
|
+
"@typescript-eslint/no-unsafe-return": 0,
|
|
33
|
+
"@typescript-eslint/no-unsafe-call": 0
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"build": "npx ts-node build.ts",
|
|
6
6
|
"lint": "eslint . --ext .ts",
|
|
7
7
|
"start": "node -r module-alias/register ./dist --env=production",
|
|
8
|
-
"
|
|
8
|
+
"dev": "nodemon",
|
|
9
9
|
"test": "nodemon --config ./spec/nodemon.json",
|
|
10
10
|
"test:no-reloading": "npx ts-node --files -r tsconfig-paths/register ./spec"
|
|
11
11
|
},
|
|
@@ -28,82 +28,8 @@
|
|
|
28
28
|
"@routes": "dist/routes",
|
|
29
29
|
"@util": "dist/util"
|
|
30
30
|
},
|
|
31
|
-
"eslintConfig": {
|
|
32
|
-
"parser": "@typescript-eslint/parser",
|
|
33
|
-
"plugins": [
|
|
34
|
-
"@typescript-eslint"
|
|
35
|
-
],
|
|
36
|
-
"extends": [
|
|
37
|
-
"eslint:recommended",
|
|
38
|
-
"plugin:@typescript-eslint/recommended",
|
|
39
|
-
"plugin:@typescript-eslint/recommended-requiring-type-checking"
|
|
40
|
-
],
|
|
41
|
-
"parserOptions": {
|
|
42
|
-
"project": "./tsconfig.json"
|
|
43
|
-
},
|
|
44
|
-
"rules": {
|
|
45
|
-
"max-len": [
|
|
46
|
-
"error",
|
|
47
|
-
{
|
|
48
|
-
"code": 100
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
"no-console": 1,
|
|
52
|
-
"no-extra-boolean-cast": 0,
|
|
53
|
-
"@typescript-eslint/restrict-plus-operands": 0,
|
|
54
|
-
"@typescript-eslint/explicit-module-boundary-types": 0,
|
|
55
|
-
"@typescript-eslint/no-explicit-any": 0,
|
|
56
|
-
"@typescript-eslint/no-floating-promises": 0,
|
|
57
|
-
"@typescript-eslint/no-unsafe-member-access": 0,
|
|
58
|
-
"@typescript-eslint/no-unsafe-assignment": 0
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
"eslintIgnore": [
|
|
62
|
-
"src/public/",
|
|
63
|
-
"build.ts"
|
|
64
|
-
],
|
|
65
31
|
"dependencies": {
|
|
66
|
-
"bcrypt": "^5.0.1",
|
|
67
|
-
"command-line-args": "^5.2.1",
|
|
68
|
-
"cookie-parser": "^1.4.6",
|
|
69
|
-
"dotenv": "^16.0.0",
|
|
70
|
-
"express": "^4.17.2",
|
|
71
|
-
"express-async-errors": "^3.1.1",
|
|
72
|
-
"helmet": "^5.0.2",
|
|
73
|
-
"http-status-codes": "^2.2.0",
|
|
74
|
-
"jet-logger": "^1.1.5",
|
|
75
|
-
"jsonfile": "^6.1.0",
|
|
76
|
-
"jsonwebtoken": "^8.5.1",
|
|
77
|
-
"module-alias": "^2.2.2",
|
|
78
|
-
"morgan": "^1.10.0",
|
|
79
|
-
"randomstring": "^1.2.2",
|
|
80
|
-
"socket.io": "^4.4.1"
|
|
81
32
|
},
|
|
82
33
|
"devDependencies": {
|
|
83
|
-
"@types/bcrypt": "^5.0.0",
|
|
84
|
-
"@types/command-line-args": "^5.2.0",
|
|
85
|
-
"@types/cookie-parser": "^1.4.2",
|
|
86
|
-
"@types/express": "^4.17.13",
|
|
87
|
-
"@types/find": "^0.2.1",
|
|
88
|
-
"@types/fs-extra": "^9.0.13",
|
|
89
|
-
"@types/jasmine": "^3.10.3",
|
|
90
|
-
"@types/jsonfile": "^6.0.1",
|
|
91
|
-
"@types/jsonwebtoken": "^8.5.8",
|
|
92
|
-
"@types/morgan": "^1.9.3",
|
|
93
|
-
"@types/node": "^17.0.15",
|
|
94
|
-
"@types/randomstring": "^1.1.8",
|
|
95
|
-
"@types/supertest": "^2.0.11",
|
|
96
|
-
"@typescript-eslint/eslint-plugin": "^5.10.2",
|
|
97
|
-
"@typescript-eslint/parser": "^5.10.2",
|
|
98
|
-
"eslint": "^8.8.0",
|
|
99
|
-
"find": "^0.3.0",
|
|
100
|
-
"fs-extra": "^10.0.0",
|
|
101
|
-
"jasmine": "^4.0.2",
|
|
102
|
-
"nodemon": "^2.0.15",
|
|
103
|
-
"socket.io-client": "^4.4.1",
|
|
104
|
-
"supertest": "^6.2.2",
|
|
105
|
-
"ts-node": "^10.4.0",
|
|
106
|
-
"tsconfig-paths": "^3.12.0",
|
|
107
|
-
"typescript": "^4.5.5"
|
|
108
34
|
}
|
|
109
35
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import './pre-start'; // Must be the first import
|
|
2
2
|
import logger from 'jet-logger';
|
|
3
|
+
|
|
3
4
|
import server from './server';
|
|
5
|
+
import envVars from '@shared/env-vars';
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
// Constants
|
|
7
|
-
const serverStartMsg = 'Express server started on port: '
|
|
8
|
-
port = (process.env.PORT || 3000);
|
|
9
|
+
const serverStartMsg = 'Express server started on port: ';
|
|
9
10
|
|
|
10
11
|
// Start server
|
|
11
|
-
server.listen(port, () => {
|
|
12
|
-
logger.info(serverStartMsg + port);
|
|
12
|
+
server.listen(envVars.port, () => {
|
|
13
|
+
logger.info(serverStartMsg + envVars.port);
|
|
13
14
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
nodeEnv: process.env.NODE_ENV ?? '',
|
|
3
|
-
port: process.env.PORT ?? 0,
|
|
2
|
+
nodeEnv: (process.env.NODE_ENV ?? ''),
|
|
3
|
+
port: (process.env.PORT ?? 0),
|
|
4
4
|
cookieProps: {
|
|
5
5
|
key: 'ExpressGeneratorTs',
|
|
6
|
-
secret: process.env.COOKIE_SECRET ?? '',
|
|
6
|
+
secret: (process.env.COOKIE_SECRET ?? ''),
|
|
7
7
|
options: {
|
|
8
8
|
httpOnly: true,
|
|
9
9
|
signed: true,
|
|
@@ -14,7 +14,7 @@ export default {
|
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
16
|
jwt: {
|
|
17
|
-
secret: process.env.JWT_SECRET ?? '',
|
|
18
|
-
exp: process.env.COOKIE_EXP ?? '', // exp at the same time as the cookie
|
|
17
|
+
secret: (process.env.JWT_SECRET ?? ''),
|
|
18
|
+
exp: (process.env.COOKIE_EXP ?? ''), // exp at the same time as the cookie
|
|
19
19
|
},
|
|
20
|
-
};
|
|
20
|
+
} as const;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-generator-typescript",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"description": "Generate new Express applications similar to express-generate which but sets it up to use TypeScript instead",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"express-generator-typescript": "node bin/cli.js",
|