-
Notifications
You must be signed in to change notification settings - Fork 5
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
16 changed files
with
727 additions
and
34 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,18 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
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 @@ | ||
# This file is generated by Nx. | ||
# | ||
# Build the docker image with `npx nx docker-build search`. | ||
# Tip: Modify "docker-build" options in project.json to change docker build args. | ||
# | ||
# Run the container with `docker run -p 3000:3000 -t search`. | ||
FROM docker.io/node:lts-alpine | ||
|
||
ENV HOST=0.0.0.0 | ||
ENV PORT=3000 | ||
|
||
WORKDIR /app | ||
|
||
RUN addgroup --system search && \ | ||
adduser --system -G search search | ||
|
||
COPY dist/apps/search search/ | ||
RUN chown -R search:search . | ||
|
||
# You can remove this install step if you build with `--bundle` option. | ||
# The bundled output will include external dependencies. | ||
RUN npm --prefix search --omit=dev -f install | ||
|
||
CMD [ "node", "search" ] |
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,10 @@ | ||
export default { | ||
displayName: 'search', | ||
preset: '../../jest.preset.js', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }], | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/apps/search', | ||
}; |
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,73 @@ | ||
{ | ||
"name": "search", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "apps/search/src", | ||
"projectType": "application", | ||
"tags": [], | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/esbuild:esbuild", | ||
"outputs": ["{options.outputPath}"], | ||
"defaultConfiguration": "production", | ||
"options": { | ||
"platform": "node", | ||
"outputPath": "dist/apps/search", | ||
"format": ["cjs"], | ||
"bundle": false, | ||
"main": "apps/search/src/main.ts", | ||
"tsConfig": "apps/search/tsconfig.app.json", | ||
"assets": ["apps/search/src/assets"], | ||
"generatePackageJson": true, | ||
"esbuildOptions": { | ||
"sourcemap": true, | ||
"outExtension": { | ||
".js": ".js" | ||
} | ||
} | ||
}, | ||
"configurations": { | ||
"development": {}, | ||
"production": { | ||
"generateLockfile": true, | ||
"esbuildOptions": { | ||
"sourcemap": false, | ||
"outExtension": { | ||
".js": ".js" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"serve": { | ||
"executor": "@nx/js:node", | ||
"defaultConfiguration": "development", | ||
"dependsOn": ["build"], | ||
"options": { | ||
"buildTarget": "search:build", | ||
"runBuildTargetDependencies": false | ||
}, | ||
"configurations": { | ||
"development": { | ||
"buildTarget": "search:build:development" | ||
}, | ||
"production": { | ||
"buildTarget": "search:build:production" | ||
} | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/eslint:lint" | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "apps/search/jest.config.ts" | ||
} | ||
}, | ||
"docker-build": { | ||
"dependsOn": ["build"], | ||
"command": "docker build -f apps/search/Dockerfile . -t search" | ||
} | ||
} | ||
} |
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,20 @@ | ||
import Fastify, { FastifyInstance } from 'fastify'; | ||
import { app } from './app'; | ||
|
||
describe('GET /', () => { | ||
let server: FastifyInstance; | ||
|
||
beforeEach(() => { | ||
server = Fastify(); | ||
server.register(app); | ||
}); | ||
|
||
it('should respond with a message', async () => { | ||
const response = await server.inject({ | ||
method: 'GET', | ||
url: '/', | ||
}); | ||
|
||
expect(response.json()).toEqual({ message: 'Hello API' }); | ||
}); | ||
}); |
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,27 @@ | ||
import * as path from 'path'; | ||
import { FastifyInstance } from 'fastify'; | ||
import AutoLoad from '@fastify/autoload'; | ||
|
||
/* eslint-disable-next-line */ | ||
export interface AppOptions {} | ||
|
||
export async function app(fastify: FastifyInstance, opts: AppOptions) { | ||
// Place here your custom code! | ||
|
||
// Do not touch the following lines | ||
|
||
// This loads all plugins defined in plugins | ||
// those should be support plugins that are reused | ||
// through your application | ||
fastify.register(AutoLoad, { | ||
dir: path.join(__dirname, 'plugins'), | ||
options: { ...opts }, | ||
}); | ||
|
||
// This loads all plugins defined in routes | ||
// define your routes in one of these | ||
fastify.register(AutoLoad, { | ||
dir: path.join(__dirname, 'routes'), | ||
options: { ...opts }, | ||
}); | ||
} |
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,12 @@ | ||
import { FastifyInstance } from 'fastify'; | ||
import fp from 'fastify-plugin'; | ||
import sensible from '@fastify/sensible'; | ||
|
||
/** | ||
* This plugins adds some utilities to handle http errors | ||
* | ||
* @see https://github.com/fastify/fastify-sensible | ||
*/ | ||
export default fp(async function (fastify: FastifyInstance) { | ||
fastify.register(sensible); | ||
}); |
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,7 @@ | ||
import { FastifyInstance } from 'fastify'; | ||
|
||
export default async function (fastify: FastifyInstance) { | ||
fastify.get('/', async function () { | ||
return { message: 'Hello API' }; | ||
}); | ||
} |
Empty file.
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,23 @@ | ||
import Fastify from 'fastify'; | ||
import { app } from './app/app'; | ||
|
||
const host = process.env.HOST ?? 'localhost'; | ||
const port = process.env.PORT ? Number(process.env.PORT) : 3001; | ||
|
||
// Instantiate Fastify with some config | ||
const server = Fastify({ | ||
logger: true, | ||
}); | ||
|
||
// Register your application as a normal plugin. | ||
server.register(app); | ||
|
||
// Start listening. | ||
server.listen({ port, host }, (err) => { | ||
if (err) { | ||
server.log.error(err); | ||
process.exit(1); | ||
} else { | ||
console.log(`[ ready ] http://${host}:${port}`); | ||
} | ||
}); |
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,10 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["node"] | ||
}, | ||
"include": ["src/**/*.ts"], | ||
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] | ||
} |
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,16 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.app.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
], | ||
"compilerOptions": { | ||
"esModuleInterop": true | ||
} | ||
} |
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,14 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"include": [ | ||
"jest.config.ts", | ||
"src/**/*.test.ts", | ||
"src/**/*.spec.ts", | ||
"src/**/*.d.ts" | ||
] | ||
} |
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
Oops, something went wrong.