Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
fix: fix test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
fox1t committed Feb 7, 2020
1 parent ebccf4d commit 00868f9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 38 deletions.
11 changes: 5 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ module.exports = {
'react/jsx-wrap-multilines': 'off',
'no-param-reassign': ['error', { props: false }],
'import/prefer-default-export': 'off',
'@typescript-eslint/member-delimiter-style': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
curly: ['error', 'all'],
'eol-last': ['error', 'always'],
'no-debugger': 'error',
'@typescript-eslint/unified-signatures': 'error',
'import/no-unresolved': 'off',
'@typescript-eslint/no-inferrable-types': ['error', { ignoreParameters: true }],
'@typescript-eslint/unified-signatures': 'error',
'@typescript-eslint/member-delimiter-style': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
}
40 changes: 40 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { join } from 'path'
import AutoLoad from 'fastify-autoload'
import { FastifyInstance } from 'fastify'
import { nextCallback } from 'fastify-plugin'
import noIcon from 'fastify-no-icon'
import helmet from 'fastify-helmet'
import qs from 'qs'
import cors from 'fastify-cors'

function HospitalRun(fastify: FastifyInstance, opts: any, next: nextCallback) {
fastify.register(cors, {
allowedHeaders: ['Content-Type', 'Authorization'],
})
fastify.register(helmet)
fastify.register(noIcon)

// This loads all application wide plugins defined in plugins folder
fastify.register(AutoLoad, {
dir: join(__dirname, 'plugins'),
includeTypeScript: true,
options: { ...opts },
})

// This loads all routes and services defined in services folder
fastify.register(AutoLoad, {
dir: join(__dirname, 'services'),
includeTypeScript: true,
options: { ...opts },
})

next()
}

HospitalRun.options = {
querystringParser: (str: string) => qs.parse(str),
logger: true,
ignoreTrailingSlash: true,
}

export = HospitalRun
32 changes: 4 additions & 28 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
// we need this file because of this issue: https://github.com/fastify/fastify-cli/issues/131
import 'make-promises-safe'
import { join } from 'path'
import qs from 'qs'
import Fastify from 'fastify'
import cors from 'fastify-cors'
import helmet from 'fastify-helmet'
import noIcon from 'fastify-no-icon'
import AutoLoad from 'fastify-autoload'
import hospitalRun from './app'

const port = Number(process.env.PORT) || 3000
const ip = process.env.IP || '0.0.0.0'

const fastify = Fastify({
querystringParser: (str: string) => qs.parse(str),
logger: true,
ignoreTrailingSlash: true,
})
fastify.register(cors, {
allowedHeaders: ['Content-Type', 'Authorization'],
})
fastify.register(helmet)
fastify.register(noIcon)

// This loads all application wide plugins defined in plugins folder
fastify.register(AutoLoad, {
dir: join(__dirname, 'plugins'),
options: {},
})

// This loads all routes and services defined in services folder
fastify.register(AutoLoad, {
dir: join(__dirname, 'services'),
options: {},
})
const fastify = Fastify(hospitalRun.options)
fastify.register(hospitalRun)

if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line
const blipp = require('fastify-blipp')
fastify.register(blipp)
}
Expand Down
7 changes: 4 additions & 3 deletions src/plugins/couchdb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import fp from 'fastify-plugin'
import nano, { ServerScope, Configuration } from 'nano'
import proxy from './proxy'

const COUCHDB_URL = String(process.env.COUCHDB_URL)
const COUCHDB_URL = process.env.COUCHDB_URL ? String(process.env.COUCHDB_URL) : undefined

function couchDB(
fastify: FastifyInstance,
options: Configuration,
next: (err?: FastifyError | undefined) => void,
) {
const couch = nano(options)
const url = COUCHDB_URL || options.url
const couch = nano({ ...options, url })
fastify.decorate('couch', couch)
fastify.register(proxy, { url: COUCHDB_URL })
fastify.register(proxy, { url })
next()
}

Expand Down
4 changes: 3 additions & 1 deletion test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import App from '../src/app'

// Fill in this config with all the configurations
// needed for testing the application
export const config = () => ({})
export const config = () => ({
url: 'https://localhost:5984',
})

// automatically build and tear down our instance
export const build = (t: any) => {
Expand Down

0 comments on commit 00868f9

Please sign in to comment.