Skip to content

Commit

Permalink
update repo to include static assets served via express; also handle …
Browse files Browse the repository at this point in the history
…arbitrary secret keys for HSxxx if passed
  • Loading branch information
tmountjr committed Aug 13, 2024
1 parent 05d3e75 commit e323ccf
Show file tree
Hide file tree
Showing 8 changed files with 1,431 additions and 164 deletions.
8 changes: 7 additions & 1 deletion examples/v7-ef-jwt-validation/edge-functions/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ export async function handleHttpRequest(request, context) {
// For RSxxx, ESxxx, and PSxxx algorithms, a public key is required instead.
// The public key is expected to be part of the request payload and be named pubKey;
// the secret key SHOULD NOT be part of the payload.
// Note that for demo purposes (being able to set an arbitrary signing key) this
// version of the EF will use the secret from `pubKey` if it exists.
if (/^HS/i.test(alg)) {
validationComponent = process.env.JWT_SECRET
if ('pubKey' in other) {
validationComponent = other.pubKey
} else {
validationComponent = process.env.JWT_SECRET
}
} else if (/^[REP]S/i.test(alg)) {
validationComponent = KEYUTIL.getKey(other.pubKey)
} else {
Expand Down
46 changes: 11 additions & 35 deletions examples/v7-ef-jwt-validation/edgio.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// You should commit this file to source control.
// Learn more about this file at https://docs.edg.io/guides/edgio_config
module.exports = {
connector: '@edgio/express',

// The name of the site in Edgio to which this app should be deployed.
name: "edgio-v7-ef-jwt-validation-example",

Expand All @@ -17,32 +19,6 @@ module.exports = {
// If omitted this will default to the "Automatic Purging" configuration on the environment's Caching tab.
// purgeCacheOnDeploy: false,

origins: [
{
// The name of the backend origin
name: "origin",

// Use the following to override the host header sent from the browser when connecting to the origin
override_host_header: "httpbin.org",

// The list of origin hosts to which to connect
hosts: [
{
// The domain name or IP address of the origin server
location: "httpbin.org",
},
],

tls_verify: {
use_sni: true,
sni_hint_and_strict_san_check: "httpbin.org",
},

// Uncomment the following to configure a shield
// shields: { us_east: 'DCD' },
},
],

// Uncomment the following to specify environment specific configs
// environments: {
// production: {
Expand All @@ -66,15 +42,15 @@ module.exports = {
// },

// Options for hosting serverless functions on Edgio
// serverless: {
// // Set to true to include all packages listed in the dependencies property of package.json when deploying to Edgio.
// // This option generally isn't needed as Edgio automatically includes all modules imported by your code in the bundle that
// // is uploaded during deployment
// includeNodeModules: true,
//
// // Include additional paths that are dynamically loaded by your app at runtime here when building the serverless bundle.
// include: ['views/**/*'],
// },
serverless: {
// // Set to true to include all packages listed in the dependencies property of package.json when deploying to Edgio.
// // This option generally isn't needed as Edgio automatically includes all modules imported by your code in the bundle that
// // is uploaded during deployment
// includeNodeModules: true,

// Include additional paths that are dynamically loaded by your app at runtime here when building the serverless bundle.
include: ['static'],
},

// The maximum number of URLs that will be concurrently prerendered during deployment when static prerendering is enabled.
// Defaults to 200, which is the maximum allowed value.
Expand Down
13 changes: 13 additions & 0 deletions examples/v7-ef-jwt-validation/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const path = require('path')
const express = require('express')

const PORT = process.env.PORT || 3000

const app = express()
app.use(express.static(path.join(__dirname, 'static'), {
extensions: ['html']
}))

app.listen(PORT, () => {
`Express server running on port ${PORT}.`
})
Loading

0 comments on commit e323ccf

Please sign in to comment.