Skip to content
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

Adding the iris-ws.js file to CDNJS #1047

Closed
dibyendu opened this issue Jul 24, 2018 · 6 comments
Closed

Adding the iris-ws.js file to CDNJS #1047

dibyendu opened this issue Jul 24, 2018 · 6 comments

Comments

@dibyendu
Copy link
Contributor

dibyendu commented Jul 24, 2018

Hi, for the websocket client-side module, currently iris has one .ts file here: https://github.com/kataras/iris/blob/master/websocket/client.ts, which is embedded as javascript in the client.go file

var ClientSource = []byte(`var websocketStringMessageType = 0;
and it is being served from within the .go file itself (on an endpoint called /iris-ws.js).

Here is a working snippet:

import (
    "github.com/kataras/iris"
    "github.com/kataras/iris/websocket"
)

func main() {
app := iris.New()
// serve the javascript built'n client-side library,
// see websockets.html script tags, this path is used.
app.Any("/iris-ws.js", func(ctx iris.Context) {
    ctx.Write(websocket.ClientSource)
})

But it would be nice if we could host the client side javascript on some CDN and server it from there. CDNJS is one such free CDN service provider. But it appears that they only serve Javascript and NOT Typescript or javascript embedded in .go.

I've already opened a request on CDNJS for hosting the iris-ws.js file. This is the issue: cdnjs/cdnjs#12884

But since there is no .js file in the iris repository, they seem to be finding it difficult to host.

Is it possible for you to add the client.js or iris-ws.js file along with the client.ts file in https://github.com/kataras/iris/blob/master/websocket/ ?

The client.ts can be converted to iris-ws.js as follows:

npm install -g typescript
tsc client.ts 

or using this online service: https://www.typescriptlang.org/play

@kataras
Copy link
Owner

kataras commented Jul 25, 2018

Done @dibyendu , thank you a lot for this!

P.S: I know how to convert typescript to javascipt and the opossite, I am a typescript enthusiast from the beginning of its life :P

@dibyendu
Copy link
Contributor Author

Hi @kataras please add the client.min.js file as well to the repo, so that I can add it to the CDNJS autoupdate section here: https://github.com/cdnjs/cdnjs/pull/12896/files#diff-9a0f3365f38ba05fa353b7c8818ce584R12

@kataras
Copy link
Owner

kataras commented Jul 30, 2018

Oups sorry, your PR is merged, thank you a lot @dibyendu!

@dibyendu
Copy link
Contributor Author

Hi @kataras, there is a good news. The client side library iris-ws.js is now part of CDNJS.
There are 2 files, client.js and client.min.js: https://cdnjs.com/libraries/iris-ws
Now you can mention this in the relevant README and/or change the part of the code accordingly.

<!doctype html>
<html>
<head>
-	<script type="text/javascript" src="/iris-ws.js"></script>
+	<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/iris-ws/10.7.0/client.min.js"></script>
</head>
	<body>
	</body>
</html>

Thanks

@kataras
Copy link
Owner

kataras commented Aug 23, 2018

That's wonderful news, so end-devs are not necessarily need to serve the websocket.ClientSource manually if they are online. I will put a note at the v11 branch, thank you a lot for your contribution @dibyendu

@kataras
Copy link
Owner

kataras commented Jul 23, 2019

Update

As of 11.2 release, the above ^ iris javascript file is obselete. Use that instead:

<script src="https://cdn.jsdelivr.net/npm/neffos.js@latest/dist/neffos.min.js"></script>

@kataras kataras closed this as completed Jul 23, 2019
github-actions bot pushed a commit to goproxies/github.com-kataras-iris that referenced this issue Jul 27, 2020


Former-commit-id: c76a6cf70ce11ac1beeafb9b80559f2bf0274b9f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants