This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
169 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
COUCHDB_URL="http://localhost:5984" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
// Use IntelliSense to learn about possible Node.js debug attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Attach", | ||
"type": "node", | ||
"protocol": "inspector", | ||
"request": "attach", | ||
"restart": true, | ||
"address": "localhost", | ||
"sourceMaps": true, | ||
"skipFiles": [ | ||
"node_modules" | ||
], | ||
"port": 9229 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"eslint.autoFixOnSave": true, | ||
"eslint.enable": true, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
}, | ||
"eslint.validate": [ | ||
"javascript", | ||
"javascriptreact", | ||
{ | ||
"autoFix": true, | ||
"language": "typescript" | ||
}, | ||
{ | ||
"autoFix": true, | ||
"language": "typescriptreact" | ||
} | ||
] | ||
"typescript", | ||
"typescriptreact" | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"httpd": { | ||
"port": 5984 | ||
}, | ||
"log": { | ||
"file": "./db/pouchdb.log" | ||
}, | ||
"couchdb": { | ||
"database_dir": "./db/data", | ||
"uuid": "ae0918af-6019-4679-bbde-0f774c342d8b" | ||
}, | ||
"pouchdb_server": { | ||
"no-stdout-logs": true | ||
}, | ||
"admins": { | ||
"dev": "-pbkdf2-f7588c0cc574a0f3d428bf9f1ab9f96a593313f7,13019f18c1801df1c01bb17e1dd15b1871ab1f3104151125,10" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,53 @@ | ||
// we need this file because of this issue: https://github.com/fastify/fastify-cli/issues/131 | ||
import 'make-promises-safe' | ||
import blipp from 'fastify-blipp' | ||
|
||
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 app from './app' | ||
const port = Number(process.env.PORT) || 3000 | ||
const ip = process.env.IP || '0.0.0.0' | ||
|
||
console.time('Boot Time') | ||
const fastify = Fastify(app.options) | ||
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) | ||
|
||
fastify.register(blipp) | ||
fastify.register(app) | ||
// This loads all application wide plugins defined in plugins folder | ||
fastify.register(AutoLoad, { | ||
dir: join(__dirname, 'plugins'), | ||
options: {}, | ||
}) | ||
|
||
fastify.listen((process.env.PORT as any) || 3000, '0.0.0.0', err => { | ||
// This loads all routes and services defined in services folder | ||
fastify.register(AutoLoad, { | ||
dir: join(__dirname, 'services'), | ||
options: {}, | ||
}) | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
const blipp = require('fastify-blipp') | ||
fastify.register(blipp) | ||
} | ||
|
||
fastify.listen(port, ip, err => { | ||
if (err) { | ||
console.log(err) | ||
fastify.log.error(err) | ||
process.exit(1) | ||
} | ||
fastify.blipp() | ||
|
||
console.timeEnd('Boot Time') | ||
console.log(`Server listening on port ${(fastify.server as any).address().port}`) | ||
if (process.env.NODE_ENV !== 'production') { | ||
fastify.blipp() | ||
fastify.log.info( | ||
`Database username 'dev', password 'dev, GUI running on: http://localhost:5984/_utils`, | ||
) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { FastifyInstance, FastifyError } from 'fastify' | ||
import fp from 'fastify-plugin' | ||
import nano, { ServerScope, Configuration } from 'nano' | ||
import proxy from './proxy' | ||
|
||
const COUCHDB_URL = String(process.env.COUCHDB_URL) | ||
|
||
function couchDB( | ||
fastify: FastifyInstance, | ||
options: Configuration, | ||
next: (err?: FastifyError | undefined) => void, | ||
) { | ||
const couch = nano(options) | ||
fastify.decorate('couch', couch) | ||
fastify.register(proxy, { url: COUCHDB_URL }) | ||
next() | ||
} | ||
|
||
couchDB.autoConfig = { | ||
url: COUCHDB_URL, | ||
} | ||
|
||
export = fp(couchDB) | ||
|
||
declare module 'fastify' { | ||
interface FastifyInstance { | ||
couch: ServerScope | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { FastifyInstance, FastifyError } from 'fastify' | ||
import proxy from 'fastify-http-proxy' | ||
|
||
interface Options { | ||
url: string | ||
} | ||
|
||
function couchDBProxy( | ||
fastify: FastifyInstance, | ||
options: Options, | ||
next: (err?: FastifyError | undefined) => void, | ||
) { | ||
fastify.register(proxy, { | ||
upstream: options.url, | ||
prefix: '/_db', | ||
}) | ||
next() | ||
} | ||
|
||
couchDBProxy.autoConfig = { | ||
url: process.env.COUCHDB_URL, | ||
} | ||
|
||
export = couchDBProxy |