-
Notifications
You must be signed in to change notification settings - Fork 1
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
12 changed files
with
229 additions
and
210 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
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,39 +1,39 @@ | ||
name: Release and Publish | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- alpha | ||
- beta | ||
- next | ||
push: | ||
branches: | ||
- main | ||
- alpha | ||
- beta | ||
- next | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20.x | ||
|
||
- name: npm install | ||
run: npm install | ||
|
||
- name: npm lint | ||
run: npm run lint | ||
|
||
- name: npm types | ||
run: npm run types | ||
|
||
- name: npm test | ||
run: npm test | ||
|
||
- name: npx semantic-release | ||
run: npx semantic-release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
|
||
- name: npm install | ||
run: npm install | ||
|
||
- name: npm lint | ||
run: npm run lint | ||
|
||
- name: npm types | ||
run: npm run types | ||
|
||
- name: npm test | ||
run: npm test | ||
|
||
- name: npx semantic-release | ||
run: npx semantic-release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
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 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"tabWidth": 4, | ||
"overrides": [ | ||
{ | ||
"files": ["*.json", "*.yml"], | ||
"options": { | ||
"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,22 @@ | ||
import prettierConfig from 'eslint-config-prettier'; | ||
import prettierPlugin from 'eslint-plugin-prettier/recommended'; | ||
import globals from 'globals'; | ||
import js from '@eslint/js'; | ||
|
||
export default [ | ||
js.configs.recommended, | ||
prettierConfig, | ||
prettierPlugin, | ||
{ | ||
languageOptions: { | ||
globals: { | ||
...globals.node, | ||
...globals.browser, | ||
global: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
ignores: ['coverage/*', '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
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,81 +1,86 @@ | ||
/* eslint-disable no-param-reassign */ | ||
/* eslint-disable consistent-return */ | ||
|
||
import { HttpIncoming, pathnameBuilder } from '@podium/utils'; | ||
import fp from 'fastify-plugin'; | ||
|
||
export default fp( | ||
(fastify, options, done) => { | ||
const layout = /** @type {import('@podium/layout').default} */ (options); | ||
|
||
// Decorate reply with .app.podium we can write to throughout the request | ||
fastify.decorateReply('app', null); | ||
fastify.addHook('onRequest', async (request, reply) => { | ||
// namespace | ||
// @ts-ignore We type this for our consumers with fixup.sh | ||
reply.app = reply.app || {}; | ||
// used to pass additional values to HttpIncoming | ||
// @ts-ignore We type this for our consumers with fixup.sh | ||
reply.app.params = reply.app.params || {}; | ||
// used to hold the HttpIncoming object | ||
// @ts-ignore We type this for our consumers with fixup.sh | ||
reply.app.podium = new HttpIncoming( | ||
request.raw, | ||
reply.raw, | ||
// @ts-ignore We type this for our consumers with fixup.sh | ||
reply.app.params, | ||
const layout = /** @type {import('@podium/layout').default} */ ( | ||
options | ||
); | ||
// @ts-ignore We type this for our consumers with fixup.sh | ||
reply.app.podium = await layout.process(reply.app.podium, { | ||
proxy: false, | ||
}); | ||
}); | ||
|
||
// Decorate response with .podiumSend() method | ||
fastify.decorateReply('podiumSend', | ||
/** | ||
* @see https://podium-lib.io/docs/api/layout#respodiumsendfragment | ||
* @param {unknown} payload | ||
* @param {unknown[]} args | ||
*/ | ||
function podiumSend(payload, ...args) { | ||
this.type('text/html; charset=utf-8'); // "this" here is the fastify 'Reply' object | ||
// @ts-ignore We type this for our consumers with fixup.sh | ||
this.send(layout.render(this.app.podium, payload, ...args)); | ||
}); | ||
// Decorate reply with .app.podium we can write to throughout the request | ||
fastify.decorateReply('app', null); | ||
fastify.addHook('onRequest', async (request, reply) => { | ||
// namespace | ||
// @ts-ignore We type this for our consumers with fixup.sh | ||
reply.app = reply.app || {}; | ||
// used to pass additional values to HttpIncoming | ||
// @ts-ignore We type this for our consumers with fixup.sh | ||
reply.app.params = reply.app.params || {}; | ||
// used to hold the HttpIncoming object | ||
// @ts-ignore We type this for our consumers with fixup.sh | ||
reply.app.podium = new HttpIncoming( | ||
request.raw, | ||
reply.raw, | ||
// @ts-ignore We type this for our consumers with fixup.sh | ||
reply.app.params, | ||
); | ||
// @ts-ignore We type this for our consumers with fixup.sh | ||
reply.app.podium = await layout.process(reply.app.podium, { | ||
proxy: false, | ||
}); | ||
}); | ||
|
||
// Mount proxy route as an instance so its executed only on | ||
// the registered path. Iow: the proxy check is not run on | ||
// any other routes | ||
fastify.register((instance, opts, next) => { | ||
const pathname = pathnameBuilder( | ||
layout.httpProxy.pathname, | ||
layout.httpProxy.prefix, | ||
'/*', | ||
// Decorate response with .podiumSend() method | ||
fastify.decorateReply( | ||
'podiumSend', | ||
/** | ||
* @see https://podium-lib.io/docs/api/layout#respodiumsendfragment | ||
* @param {unknown} payload | ||
* @param {unknown[]} args | ||
*/ | ||
function podiumSend(payload, ...args) { | ||
this.type('text/html; charset=utf-8'); // "this" here is the fastify 'Reply' object | ||
// @ts-ignore We type this for our consumers with fixup.sh | ||
this.send(layout.render(this.app.podium, payload, ...args)); | ||
}, | ||
); | ||
|
||
// Allow all content types for proxy requests | ||
// https://github.com/fastify/fastify/blob/master/docs/ContentTypeParser.md#catch-all | ||
instance.addContentTypeParser('*', (req, payload, cb) => { | ||
// @ts-ignore | ||
cb(); | ||
}); | ||
// Mount proxy route as an instance so its executed only on | ||
// the registered path. Iow: the proxy check is not run on | ||
// any other routes | ||
fastify.register((instance, opts, next) => { | ||
const pathname = pathnameBuilder( | ||
layout.httpProxy.pathname, | ||
layout.httpProxy.prefix, | ||
'/*', | ||
); | ||
|
||
instance.addHook('preHandler', async (req, reply) => { | ||
// @ts-ignore We type this for our consumers with fixup.sh | ||
const incoming = await layout.httpProxy.process(reply.app.podium); | ||
if (incoming.proxy) return; | ||
return incoming; | ||
}); | ||
// Allow all content types for proxy requests | ||
// https://github.com/fastify/fastify/blob/master/docs/ContentTypeParser.md#catch-all | ||
instance.addContentTypeParser('*', (req, payload, cb) => { | ||
// @ts-ignore | ||
cb(); | ||
}); | ||
|
||
instance.all(pathname, (req, reply) => { | ||
reply.code(404).send('Not found'); | ||
}); | ||
instance.addHook('preHandler', async (req, reply) => { | ||
const incoming = await layout.httpProxy.process( | ||
// @ts-ignore We type this for our consumers with fixup.sh | ||
reply.app.podium, | ||
); | ||
if (incoming.proxy) return; | ||
return incoming; | ||
}); | ||
|
||
instance.all(pathname, (req, reply) => { | ||
reply.code(404).send('Not found'); | ||
}); | ||
|
||
next(); | ||
}); | ||
next(); | ||
}); | ||
|
||
done(); | ||
}, { | ||
name: 'podium-layout', | ||
}); | ||
done(); | ||
}, | ||
{ | ||
name: 'podium-layout', | ||
}, | ||
); |
Oops, something went wrong.