Skip to content

Commit

Permalink
Merge pull request #1 from modscleo4/midori
Browse files Browse the repository at this point in the history
Switch to Midori framework
  • Loading branch information
modscleo4 authored Mar 14, 2023
2 parents af7104f + 7659087 commit 28c9667
Show file tree
Hide file tree
Showing 77 changed files with 3,962 additions and 4,729 deletions.
21 changes: 21 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
OPENID_AUTH_URL=https://auth.example.com/realms/mail/protocol/openid-connect/auth
OPENID_TOKEN_URL=https://auth.example.com/realms/mail/protocol/openid-connect/token
OPENID_IDENTITY_URL=https://auth.example.com/realms/mail/protocol/openid-connect/userinfo
OPENID_REDIRECT_URL=http://localhost:3000/auth/callback
OPENID_CLIENT_ID=chess
OPENID_CLIENT_SECRET=

DATABASE_URL=postgresql://postgres:postgres@localhost:5432/apiframework

JWS_ALGORITHM=RS256
JWS_SECRET=secret
JWS_PUBLIC_KEY=./keys/jws_public.pem
JWS_PRIVATE_KEY=./keys/jws_private.pem

JWE_ALGORITHM=RSA-OAEP
JWE_ENCRYPTION=A256GCM
JWE_SECRET=secret
JWE_PUBLIC_KEY=./keys/jwe_public.pem
JWE_PRIVATE_KEY=./keys/jwe_private.pem

EXPOSE_ERRORS=true
50 changes: 50 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Create and publish a Docker image

on:
push:
branches: ['main']

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Keys
keys/

# Logs
logs
*.log
Expand Down
45 changes: 45 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
// Use o IntelliSense para saber mais sobre os atributos possíveis.
// Focalizar para exibir as descrições dos atributos existentes.
// Para obter mais informações, acesse: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "NPM Start (Dev)",
"skipFiles": [
"<node_internals>/**"
],
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
"dev"
]
},
{
"type": "node",
"request": "launch",
"name": "NPM Start (Prod)",
"skipFiles": [
"<node_internals>/**"
],
"preLaunchTask": {
"type": "npm",
"script": "build"
},
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
"start"
]
},
{
"type": "node",
"request": "attach",
"name": "Node: Attach Nodemon",
"processId": "${command:PickProcess}",
"restart": true
}
]
}
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:18-alpine

WORKDIR /app

COPY . .
RUN rm -f .env

RUN npm ci; \
npx prisma generate; \
npm run build; \
npm run generateKeys; \
npm prune --production

EXPOSE 3000

CMD ["npm", "run", "start"]
33 changes: 33 additions & 0 deletions bin/generateKeys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import crypto from "node:crypto";
import { existsSync } from "node:fs";
import { mkdir, writeFile } from "node:fs/promises";

/**
*
* @param {'rsa'|'ec'} alg
*/
function generateKeypair(alg) {
return crypto.generateKeyPairSync(alg, {
publicKeyEncoding: {
format: 'pem',
type: 'spki'
},
privateKeyEncoding: {
format: 'pem',
type: 'pkcs8',
},
...(alg === 'ec' ? { namedCurve: 'secp521r1' } : { modulusLength: 2048 })
});
}

if (!existsSync('./keys')) {
await mkdir('./keys');
}

const { publicKey: jwsPublicKey, privateKey: jwsPrivateKey } = generateKeypair('rsa');
await writeFile('./keys/jws_public.pem', jwsPublicKey, { encoding: 'utf8' });
await writeFile('./keys/jws_private.pem', jwsPrivateKey, { encoding: 'utf8' });

const { publicKey: jwePublicKey, privateKey: jwePrivateKey } = generateKeypair('rsa');
await writeFile('./keys/jwe_public.pem', jwePublicKey, { encoding: 'utf8' });
await writeFile('./keys/jwe_private.pem', jwePrivateKey, { encoding: 'utf8' });
29 changes: 29 additions & 0 deletions bin/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Thanks to @charles-allen
* @see https://github.com/TypeStrong/ts-node/discussions/1450#discussioncomment-1806115
*/

import { pathToFileURL } from "url";
import { resolve as resolveTs, getFormat, transformSource, load } from "ts-node/esm";
import * as tsConfigPaths from 'tsconfig-paths';

export { getFormat, transformSource, load };

const { absoluteBaseUrl, paths } = tsConfigPaths.loadConfig();
const matchPath = tsConfigPaths.createMatchPath(absoluteBaseUrl, paths);

export function resolve(specifier, context, defaultResolver) {
const lastIndexOfIndex = specifier.lastIndexOf('/index.js');
if (lastIndexOfIndex !== -1) {
// Handle index.js
const trimmed = specifier.substring(0, lastIndexOfIndex);
const match = matchPath(trimmed);
if (match) return resolveTs(pathToFileURL(`${match}/index.js`).href, context, defaultResolver);
} else if (specifier.endsWith('.js')) {
// Handle *.js
const trimmed = specifier.substring(0, specifier.length - 3);
const match = matchPath(trimmed);
if (match) return resolveTs(pathToFileURL(`${match}.js`).href, context, defaultResolver);
}
return resolveTs(specifier, context, defaultResolver);
}
Loading

0 comments on commit 28c9667

Please sign in to comment.