Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
fix(fichiers): ajoute automatiquement les dossiers utilisés pour stoc…
Browse files Browse the repository at this point in the history
…ker les fichiers (#913)
  • Loading branch information
vmaubert authored Mar 9, 2022
1 parent 25fff3b commit de7dec8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 38 deletions.
10 changes: 10 additions & 0 deletions src/config/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import dirCreate from '../tools/dir-create'
import { DOCUMENTS_REPERTOIRES } from '../types'

export const filesInit = async () => {
await dirCreate('files').catch()

for (const documentsRepertoire of DOCUMENTS_REPERTOIRES) {
await dirCreate(`files/${documentsRepertoire}`).catch()
}
}
72 changes: 35 additions & 37 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,51 +28,49 @@ import { databaseInit } from './database/init'

import { consoleOverride, appLogger } from './config/logger'
import cookieParser from 'cookie-parser'
import { filesInit } from './config/files'

consoleOverride(appLogger)
databaseInit().then(() => {
const app = express()
filesInit().then(() => {
databaseInit().then(() => {
const app = express()

if (process.env.SENTRY_DSN) {
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.ENV === 'prod' ? 'production' : process.env.ENV
})
app.use(Sentry.Handlers.requestHandler())
}
if (process.env.SENTRY_DSN) {
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.ENV === 'prod' ? 'production' : process.env.ENV
})
app.use(Sentry.Handlers.requestHandler())
}

app.use(
cors({ credentials: true, exposedHeaders: ['Content-disposition'] }),
compression(),
cookieParser(),
authJwt,
authJwtError,
authBasic
)
app.use(rest)
app.use(
cors({ credentials: true, exposedHeaders: ['Content-disposition'] }),
compression(),
cookieParser(),
authJwt,
authJwtError,
authBasic
)
app.use(rest)

app.use('/televersement', uploadAllowedMiddleware, restUpload())
app.use('/televersement', uploadAllowedMiddleware, restUpload())

app.use('/', graphqlUpload, graphql)
app.use('/', graphqlUpload, graphql)

if (process.env.SENTRY_DSN) {
// test sentry
// app.get('/', (req, res) => {
// console.info('broke')
// throw new Error('Broke!')
// })
app.use(Sentry.Handlers.errorHandler())
}
if (process.env.SENTRY_DSN) {
app.use(Sentry.Handlers.errorHandler())
}

app.listen(port, () => {
console.info('')
console.info('URL:', url)
console.info('ENV:', process.env.ENV)
console.info('NODE_ENV:', process.env.NODE_ENV)
app.listen(port, () => {
console.info('')
console.info('URL:', url)
console.info('ENV:', process.env.ENV)
console.info('NODE_ENV:', process.env.NODE_ENV)

if (process.env.NODE_DEBUG === 'true') {
console.warn('NODE_DEBUG:', process.env.NODE_DEBUG)
}
console.info('')
if (process.env.NODE_DEBUG === 'true') {
console.warn('NODE_DEBUG:', process.env.NODE_DEBUG)
}
console.info('')
})
})
})
8 changes: 7 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,13 @@ interface IDevise {
ordre: number
}

type IDocumentRepertoire = 'demarches' | 'activites' | 'entreprises' | 'tmp'
export const DOCUMENTS_REPERTOIRES = [
'demarches',
'activites',
'entreprises',
'tmp'
] as const
type IDocumentRepertoire = typeof DOCUMENTS_REPERTOIRES[number]

interface IDocumentType {
id: string
Expand Down

0 comments on commit de7dec8

Please sign in to comment.