-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: general cleanup of copy. Add Glossary
- Loading branch information
1 parent
6d1753d
commit 873e975
Showing
7 changed files
with
120 additions
and
58 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
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,72 @@ | ||
# hyper App Middleware | ||
|
||
hyper `Middleware` allows you to extend the hyper `App` interface to support opinionated features, without having to modify the `Core` interface. | ||
|
||
`Middleware` should be function that receives the `App` instance as a parameter and returns the `App` instance, creating a chain-able collection of middleware. For example, with `express`: | ||
|
||
```ts | ||
type HyperExpressAppMiddleware = (app: Express) => Express; | ||
``` | ||
|
||
:::info | ||
It is up to the hyper `App` implementation to properly apply the `Middleware` to itself. | ||
|
||
In other words, the `Middleware` is specific to an `App` implementation | ||
::: | ||
|
||
## Middleware Examples | ||
|
||
A common use-case is to enforce authN/Z on the hyper `Server`. Here is an example of a JWT verifying middleware when using an `express`-based `App` (See [here](/docs/api-reference/rest/index)): | ||
|
||
```ts | ||
import jwt from 'npm:express-jwt' | ||
|
||
const auth = (app) => { | ||
app.use(jwt({ | ||
secret: process.env.SECRET, | ||
algorithms: ['HS256'] | ||
}).unless({ path: ['/', /^\/data$/] })) | ||
|
||
app.use('/data', jwt({ | ||
secret: process.env.ADMIN_SECRET, | ||
algorithms: ['HS256'] | ||
}) | ||
|
||
app.use((err, req, res, next) => { | ||
if (err.name === 'UnauthorizedError') { | ||
res.status(401).send({ok: false, msg: 'not authorized'}) | ||
} | ||
}) | ||
|
||
return app | ||
} | ||
``` | ||
Because hyper is modular and in this case using `express`, you could use any `express` framework middleware to manage your authN/Z process. You can add more advanced security checks for each hyper `Service` resource or even for a specific `Domain`. | ||
For example, let's say you only wanted certain clients to be able to create or destroy hyper `Data` Services on your hyper `Server`. | ||
You would modify your `Middleware` to perform special checks based on those endpoints. | ||
**Other common use-cases:** | ||
- Throttling | ||
- Additional Routes for other services, like email, or maybe _serving_ files in a hyper `Storage` service | ||
## Applying Middleware | ||
Once you've created your middleware, you'll want to apply it to your hyper `Server` | ||
In the [hyper Config file](/docs/host/hyper-config), you may specify an array of `middleware`. This `middleware` is then passed to the hyper `App` as `services.middleware` by hyper `Core` | ||
```js hyper.config.js | ||
import { auth } from "./auth.js"; | ||
|
||
export default { | ||
app: express, | ||
adapters: [ | ||
/*...*/ | ||
], | ||
middleware: [auth], | ||
}; | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Glossary | ||
|
||
### hyper Apps 🎮 | ||
|
||
The Driving Adapters in the hyper Service Framework are called `Apps` or `Apis`. This is the public interface used to interact with the hyper `Server` | ||
|
||
### hyper Core 🪨 | ||
|
||
The business layer in hyper that contains all of the hyper business logic and enforces each `Port`. `Core` also defines the `Port` that a hyper `App` invokes to interact with `Core`. | ||
|
||
### hyper Ports 🔌 | ||
|
||
The service primitive APIs defined in hyper `Core`. There are multiple `Ports` defined in the hyper Service Framework. The current ones are `Data`, `Cache`, `Storage`, `Queue`, and `Search`. | ||
|
||
### hyper Adapters 🛠 | ||
|
||
The Driven Adapters in The hyper Service Framework. Each `Adapter` implements a hyper `Port` and does the heavy lifting of communicating with an underlying technology being used to power the `Port`. | ||
|
||
Generally, these are referred using the hyper `Port` names ie. `Data` Adapter, `Cache` Adapter, `Storage` Adapter, `Queue` Adapter, and `Search` Adapter | ||
|
||
You can see many of them that the Core team has implemented [here](https://github.com/hyper63?q=hyper-adapter&type=all&language=&sort=) | ||
|
||
### hyper Services | ||
|
||
The composed components described above: | ||
|
||
- A hyper `App` | ||
- hyper `Core` | ||
- A hyper `Adapter` | ||
|
||
Generally, these are referred using the hyper `Port` names ie. `Data` Service, `Cache` Service, `Storage` Service, `Queue` Service, and `Search` Service |
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