-
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(app): add initial Render blueprint and hyper app
- Loading branch information
1 parent
3037352
commit 31a58a2
Showing
5 changed files
with
93 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,18 @@ | ||
FROM denoland/deno:alpine | ||
|
||
WORKDIR /app | ||
|
||
# Prefer not to run as root. | ||
USER deno | ||
|
||
# Cache the dependencies as a layer (the following two steps are re-run only when deps.ts is modified). | ||
# Ideally cache deps.ts will download and compile _all_ external files used in main.ts. | ||
COPY deps.ts . | ||
RUN deno cache deps.ts | ||
|
||
# These steps will be re-run upon each file change in your working directory: | ||
ADD . . | ||
# Compile the app so that it doesn't need to be compiled each startup/entry. | ||
RUN deno cache --reload mod.ts | ||
|
||
CMD ["run", "-A", "mod.ts"] |
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,30 @@ | ||
// deno-lint-ignore-file no-explicit-any | ||
|
||
import { | ||
jwt, | ||
type NextFunction, | ||
type Opine, | ||
type OpineRequest, | ||
type OpineResponse, | ||
} from './deps.ts'; | ||
|
||
export const authMiddleware = (secret: string) => (app: Opine) => { | ||
app.use(jwt({ secret, algorithms: ['HS256'] }).unless({ path: ['/'] })); | ||
|
||
app.use( | ||
( | ||
err: any, | ||
_req: OpineRequest, | ||
res: OpineResponse, | ||
next: NextFunction, | ||
): any => { | ||
if (err.name === 'UnauthorizedError') { | ||
return res.setStatus(401).send({ ok: false, msg: 'not authorized' }); | ||
} | ||
// Trigger the next error handler | ||
next(err); | ||
}, | ||
); | ||
|
||
return app; | ||
}; |
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,12 @@ | ||
export { expressjwt as jwt } from 'npm:express-jwt'; | ||
|
||
export { z } from 'https://deno.land/x/[email protected]/mod.ts'; | ||
export type { | ||
NextFunction, | ||
Opine, | ||
OpineRequest, | ||
OpineResponse, | ||
} from 'https://deno.land/x/[email protected]/mod.ts'; | ||
|
||
export { default as hyper } from 'https://x.nest.land/[email protected]/mod.js'; | ||
export { default as app } from 'https://x.nest.land/[email protected]/mod.js'; |
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,17 @@ | ||
import { authMiddleware } from './auth.ts'; | ||
import { app, hyper, z } from './deps.ts'; | ||
|
||
function env(key: string): string { | ||
const res = z.string().min(1).safeParse(Deno.env.get(key)); | ||
if (!res.success) { | ||
console.error(`Error with ENV VAR: ${key}`); | ||
throw res.error; | ||
} | ||
return res.data; | ||
} | ||
|
||
export default hyper({ | ||
app, | ||
adapters: [], | ||
middleware: [authMiddleware(env('SECRET'))], | ||
}); |
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,16 @@ | ||
# If your hyper app exists in a sub-directory of your repo ie. monorepo, | ||
# Set the path here to the root of your hyper configuration | ||
# rootDir: apps/hyper | ||
|
||
services: | ||
|
||
# The Hyper Application | ||
- type: web | ||
name: hyper | ||
plan: starter | ||
env: docker | ||
dockerfilePath: ./app/Dockerfile | ||
dockerContext: ./app | ||
envVars: | ||
- key: SECRET | ||
generateValue: true |