-
Notifications
You must be signed in to change notification settings - Fork 631
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
0 parents
commit 9e440a7
Showing
82 changed files
with
44,034 additions
and
0 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,11 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "npm" # See documentation for possible values | ||
directory: "/" # Location of package manifests | ||
schedule: | ||
interval: "weekly" |
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 @@ | ||
name: Run Jest Tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
defaults: | ||
run: | ||
working-directory: ./api | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run Jest tests | ||
run: npm test |
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,25 @@ | ||
name: Prettier Check | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
prettier-check: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run Prettier check | ||
run: npm run prettier:check |
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,2 @@ | ||
node_modules | ||
dist |
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 @@ | ||
{ | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"printWidth": 80, | ||
"tabWidth": 2 | ||
} |
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,58 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# 0x | ||
profile-* | ||
|
||
# mac files | ||
.DS_Store | ||
|
||
# vim swap files | ||
*.swp | ||
|
||
# webstorm | ||
.idea | ||
|
||
# vscode | ||
.vscode | ||
*code-workspace | ||
|
||
# clinic | ||
profile* | ||
*clinic* | ||
*flamegraph* |
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 @@ | ||
# Getting Started with [Fastify-CLI](https://www.npmjs.com/package/fastify-cli) | ||
|
||
This project was bootstrapped with Fastify-CLI. | ||
|
||
## Available Scripts | ||
|
||
In the project directory, you can run: | ||
|
||
### `npm run dev` | ||
|
||
To start the app in dev mode.\ | ||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser. | ||
|
||
### `npm start` | ||
|
||
For production mode | ||
|
||
### `npm run test` | ||
|
||
Run the test cases. | ||
|
||
## Learn More | ||
|
||
To learn Fastify, check out the [Fastify documentation](https://fastify.dev/docs/latest/). |
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,62 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = default_1; | ||
const node_path_1 = __importDefault(require("node:path")); | ||
const autoload_1 = __importDefault(require("@fastify/autoload")); | ||
// Pass --options via CLI arguments in command to enable these options. | ||
const options = {}; | ||
async function default_1(fastify, opts) { | ||
// 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_1.default, { | ||
dir: node_path_1.default.join(__dirname, 'plugins'), | ||
options: Object.assign({}, opts), | ||
}); | ||
// This loads all plugins defined in routes | ||
// define your routes in one of these | ||
fastify.register(autoload_1.default, { | ||
dir: node_path_1.default.join(__dirname, 'routes'), | ||
options: Object.assign({}, opts), | ||
}); | ||
} | ||
module.exports.options = options; | ||
// Start the Fastify server | ||
const start = async () => { | ||
const envToLogger = { | ||
development: { | ||
transport: { | ||
target: 'pino-pretty', | ||
options: { | ||
translateTime: 'HH:MM:ss Z', | ||
ignore: 'pid,hostname', | ||
}, | ||
}, | ||
}, | ||
production: true, | ||
test: false, | ||
}; | ||
const fastify = require('fastify')({ | ||
logger: envToLogger[process.env.NODE_ENV || 'development'], | ||
}); | ||
try { | ||
await fastify.register(require('./app')).after(() => { | ||
fastify.listen({ port: 3000 }, (err, address) => { | ||
if (err) { | ||
fastify.log.error(err); | ||
process.exit(1); | ||
} | ||
fastify.log.info(`Server listening on ${address}`); | ||
}); | ||
}); | ||
} | ||
catch (err) { | ||
fastify.log.error(err); | ||
process.exit(1); | ||
} | ||
}; | ||
start(); |
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 @@ | ||
"use strict"; | ||
// handlers/handlers.ts | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.helloHandler = helloHandler; | ||
async function helloHandler() { | ||
return { message: 'Hello, world!' }; | ||
} |
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,15 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fastify_plugin_1 = __importDefault(require("fastify-plugin")); | ||
const sensible_1 = __importDefault(require("@fastify/sensible")); | ||
/** | ||
* This plugin adds some utilities to handle HTTP errors | ||
* | ||
* @see https://github.com/fastify/fastify-sensible | ||
*/ | ||
exports.default = (0, fastify_plugin_1.default)(async function (fastify) { | ||
fastify.register(sensible_1.default); | ||
}); |
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,13 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fastify_plugin_1 = __importDefault(require("fastify-plugin")); | ||
// the use of fastify-plugin is required to be able | ||
// to export the decorators to the outer scope | ||
exports.default = (0, fastify_plugin_1.default)(async function (fastify) { | ||
fastify.decorate('someSupport', function () { | ||
return 'hugs'; | ||
}); | ||
}); |
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,34 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = default_1; | ||
const sensible_1 = __importDefault(require("@fastify/sensible")); | ||
const handlers_1 = require("../handlers/handlers"); | ||
async function default_1(fastify) { | ||
fastify.register(sensible_1.default); | ||
fastify.route({ | ||
method: 'GET', | ||
url: '/', | ||
handler: async function () { | ||
fastify.log.info('GET / route hit'); | ||
return { root: true }; | ||
}, | ||
}); | ||
// This route calls a test handler that throws an error | ||
// to test the error handling functionality of the sensible plugin | ||
fastify.route({ | ||
method: 'GET', | ||
url: '/error', | ||
handler: async function () { | ||
throw new Error('Test error'); | ||
}, | ||
}); | ||
// New route with handler | ||
fastify.route({ | ||
method: 'GET', | ||
url: '/hello', | ||
handler: handlers_1.helloHandler, | ||
}); | ||
} |
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,9 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testMatch: ['**/test/**/*.test.ts'], | ||
moduleFileExtensions: ['ts', 'js'], | ||
transform: { | ||
'^.+\\.ts$': 'ts-jest', | ||
}, | ||
}; |
Oops, something went wrong.