Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
d1str0 committed Nov 27, 2024
0 parents commit 9e440a7
Show file tree
Hide file tree
Showing 82 changed files with 44,034 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
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"
29 changes: 29 additions & 0 deletions .github/workflows/jest-tests.yml
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
25 changes: 25 additions & 0 deletions .github/workflows/prettier-check.yml
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
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 80,
"tabWidth": 2
}
58 changes: 58 additions & 0 deletions api/.gitignore
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*
24 changes: 24 additions & 0 deletions api/README.md
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/).
62 changes: 62 additions & 0 deletions api/dist/app.js
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();
7 changes: 7 additions & 0 deletions api/dist/handlers/handlers.js
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!' };
}
15 changes: 15 additions & 0 deletions api/dist/plugins/sensible.js
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);
});
13 changes: 13 additions & 0 deletions api/dist/plugins/support.js
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';
});
});
34 changes: 34 additions & 0 deletions api/dist/routes/root.js
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,
});
}
9 changes: 9 additions & 0 deletions api/jest.config.js
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',
},
};
Loading

0 comments on commit 9e440a7

Please sign in to comment.