Skip to content

Commit 4682b5a

Browse files
author
hirsch88
committed
🎨 Improve typeorm config
1 parent 98a342e commit 4682b5a

File tree

8 files changed

+232
-284
lines changed

8 files changed

+232
-284
lines changed

.env.example

+19-14
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ LOG_JSON=false
1616
LOG_OUTPUT=dev
1717

1818
#
19-
# AUTHORIZATION
20-
#
21-
AUTH_ROUTE=http://localhost:3333/tokeninfo
19+
# AUTHENTIFICATION
20+
#
21+
AUTH_JWT_CACHE=true
22+
AUTH_JWT_RATE_LIMIT=true
23+
AUTH_JWKS_REQUEST_PER_MINUTE=5
24+
AUTH_JWKS_URI=https://example.eu.auth0.com/.well-known/jwks.jso
25+
AUTH_ISSUER=https://example.eu.auth0.com/
26+
AUTH_ALGORITHMS=RS256
2227

2328
#
2429
# DATABASE
@@ -33,17 +38,17 @@ TYPEORM_SYNCHRONIZE=false
3338
TYPEORM_LOGGING=false
3439

3540
#
36-
# Additional settings (optional as defaults are in env.ts)
37-
#
38-
# TYPEORM_MIGRATIONS=
39-
# TYPEORM_MIGRATIONS_DIR=
40-
# TYPEORM_ENTITIES=
41-
# TYPEORM_SUBSCRIBERS=
42-
# CONTROLLERS=
43-
# MIDDLEWARES=
44-
# INTERCEPTORS=
45-
# QUERIES=
46-
# MUTATIONS=
41+
# PATH STRUCTRUE
42+
#
43+
TYPEORM_MIGRATIONS=src/database/migrations/**/*.ts
44+
TYPEORM_MIGRATIONS_DIR=src/database/migrations
45+
TYPEORM_ENTITIES=src/api/models/**/*{.js,.ts}.ts
46+
TYPEORM_SUBSCRIBERS=src/api/subscribers/**/*Subscriber{.js,.ts}
47+
CONTROLLERS=src/api/controllers/**/*Controller{.js,.ts}
48+
MIDDLEWARES=src/api/middlewares/**/*Middleware{.js,.ts}
49+
INTERCEPTORS=src/api/interceptors/**/*Interceptor{.js,.ts}
50+
QUERIES=src/api/queries/**/*Query{.js,.ts}
51+
MUTATIONS=src/api/mutations/**/*Mutation{.js,.ts}
4752

4853
#
4954
# GraphQL

.env.test

+21-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ LOG_JSON=false
1616
LOG_OUTPUT=dev
1717

1818
#
19-
# AUTHORIZATION
19+
# AUTHENTIFICATION
2020
#
21-
AUTH_ROUTE=http://localhost:3333/tokeninfo
21+
AUTH_JWT_CACHE=true
22+
AUTH_JWT_RATE_LIMIT=true
23+
AUTH_JWKS_REQUEST_PER_MINUTE=5
24+
AUTH_JWKS_URI=https://example.eu.auth0.com/.well-known/jwks.jso
25+
AUTH_ISSUER=https://example.eu.auth0.com/
26+
AUTH_ALGORITHMS=RS256
2227

2328
#
2429
# DATABASE
@@ -27,6 +32,20 @@ TYPEORM_CONNECTION=sqlite
2732
TYPEORM_DATABASE=./mydb.sql
2833
TYPEORM_LOGGING=false
2934

35+
#
36+
# PATH STRUCTRUE
37+
#
38+
TYPEORM_MIGRATIONS=src/database/migrations/**/*.ts
39+
TYPEORM_MIGRATIONS_DIR=src/database/migrations
40+
TYPEORM_ENTITIES=src/api/models/**/*{.js,.ts}.ts
41+
TYPEORM_SUBSCRIBERS=src/api/subscribers/**/*Subscriber{.js,.ts}
42+
CONTROLLERS=src/api/controllers/**/*Controller{.js,.ts}
43+
MIDDLEWARES=src/api/middlewares/**/*Middleware{.js,.ts}
44+
INTERCEPTORS=src/api/interceptors/**/*Interceptor{.js,.ts}
45+
QUERIES=src/api/queries/**/*Query{.js,.ts}
46+
MUTATIONS=src/api/mutations/**/*Mutation{.js,.ts}
47+
48+
3049
#
3150
# GraphQL
3251
#

.vscode/settings.json

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"cSpell.enabled": true,
44
"files.exclude": {
55
"tsconfig.build.json": true,
6-
"ormconfig.json": true
76
},
87
"importSorter.generalConfiguration.sortOnBeforeSave": true,
98
"files.trimTrailingWhitespace": true,

commands/ormconfig.ts

-31
This file was deleted.

package-scripts.js

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ module.exports = {
4242
config: {
4343
script: series(
4444
runFast('./commands/tsconfig.ts'),
45-
runFast('./commands/ormconfig.ts')
4645
),
4746
hiddenFromHelp: true
4847
},

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"ts-node": "^6.0.0",
9393
"tslint": "^5.8.0",
9494
"typedi": "^0.7.2",
95-
"typeorm": "^0.2.1",
95+
"typeorm": "^0.2.5",
9696
"typeorm-typedi-extensions": "^0.2.1",
9797
"typescript": "2.8.3",
9898
"uuid": "^3.1.0",

src/env.ts

+9-33
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,15 @@ export const env = {
2727
port: normalizePort(process.env.PORT || getOsEnv('APP_PORT')),
2828
banner: toBool(getOsEnv('APP_BANNER')),
2929
dirs: {
30-
migrations: (
31-
getOsEnvArray('TYPEORM_MIGRATIONS') ||
32-
[path.relative(path.join(process.cwd()), path.join(__dirname, 'database/migrations/**/*.ts'))]
33-
) as string[],
34-
migrationsDir: getOsEnv('TYPEORM_MIGRATIONS_DIR') || path.relative(path.join(process.cwd()), path.join(__dirname, 'database/migrations')),
35-
entities: (
36-
getOsEnvArray('TYPEORM_ENTITIES') ||
37-
[path.relative(path.join(process.cwd()), path.join(__dirname, 'api/models/**/*{.js,.ts}'))]
38-
) as string[],
39-
subscribers: (
40-
getOsEnvArray('TYPEORM_SUBSCRIBERS') ||
41-
[path.join(__dirname, 'api/subscribers/**/*Subscriber{.js,.ts}')]
42-
) as string[],
43-
controllers: (
44-
getOsEnvArray('CONTROLLERS') ||
45-
[path.join(__dirname, 'api/controllers/**/*Controller{.js,.ts}')]
46-
) as string[],
47-
middlewares: (
48-
getOsEnvArray('MIDDLEWARES') ||
49-
[path.join(__dirname, 'api/middlewares/**/*Middleware{.js,.ts}')]
50-
) as string[],
51-
interceptors: (
52-
getOsEnvArray('INTERCEPTORS') ||
53-
[path.join(__dirname, 'api/interceptors/**/*Interceptor{.js,.ts}')]
54-
) as string[],
55-
queries: (
56-
getOsEnvArray('QUERIES') ||
57-
[path.join(__dirname, 'api/queries/**/*Query{.js,.ts}')]
58-
) as string[],
59-
mutations: (
60-
getOsEnvArray('MUTATIONS') ||
61-
[path.join(__dirname, 'api/mutations/**/*Mutation{.js,.ts}')]
62-
) as string[],
30+
migrations: getOsEnvArray('TYPEORM_MIGRATIONS'),
31+
migrationsDir: getOsEnv('TYPEORM_MIGRATIONS_DIR'),
32+
entities: getOsEnvArray('TYPEORM_ENTITIES'),
33+
subscribers: getOsEnvArray('TYPEORM_SUBSCRIBERS'),
34+
controllers: getOsEnvArray('CONTROLLERS'),
35+
middlewares: getOsEnvArray('MIDDLEWARES'),
36+
interceptors: getOsEnvArray('INTERCEPTORS'),
37+
queries: getOsEnvArray('QUERIES'),
38+
mutations: getOsEnvArray('MUTATIONS'),
6339
},
6440
},
6541
log: {

0 commit comments

Comments
 (0)