Skip to content

Commit 0145430

Browse files
committed
initial commit
0 parents  commit 0145430

17 files changed

+411
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package.json
2+
package-lock.json
3+
node_modules/

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# hooked.sh - WebSockets over HTTP
2+
3+
hooked.sh lets you connect to WebSockets from your serverless apps by forwarding events over regular HTTP calls to your application.

callbacktest.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var http = require('http')
2+
http.createServer(function (req, res) {
3+
if (req.method.toLowerCase() == 'post') {
4+
let data = ''
5+
req.on('data', chunk => {
6+
data += chunk
7+
})
8+
req.on('end', () => {
9+
console.log("POST - " + data)
10+
res.end()
11+
});
12+
} else {
13+
res.end()
14+
}
15+
}).listen(8009)

js/lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
throw new Error("This package is currently just a placeholder. Stay tuned https://hooked.sh/")

server/.formatter.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Used by "mix format"
2+
[
3+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
4+
]

server/.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where third-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
# Ignore package tarball (built via "mix hex.build").
23+
hooked-*.tar
24+
25+
# Temporary files, for example, from tests.
26+
/tmp/

server/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Hooked
2+
3+
**TODO: Add description**
4+
5+
## Installation
6+
7+
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
8+
by adding `hooked` to your list of dependencies in `mix.exs`:
9+
10+
```elixir
11+
def deps do
12+
[
13+
{:hooked, "~> 0.1.0"}
14+
]
15+
end
16+
```
17+
18+
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
19+
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
20+
be found at <https://hexdocs.pm/hooked>.
21+

server/lib/hooked.ex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defmodule Hooked do
2+
@moduledoc """
3+
Documentation for `Hooked`.
4+
"""
5+
6+
@doc """
7+
Hello world.
8+
9+
## Examples
10+
11+
iex> Hooked.hello()
12+
:world
13+
14+
"""
15+
def hello do
16+
:world
17+
end
18+
end

server/lib/hooked/application.ex

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
defmodule Hooked.Application do
2+
# See https://hexdocs.pm/elixir/Application.html
3+
# for more information on OTP Applications
4+
@moduledoc false
5+
6+
use Application
7+
8+
@impl true
9+
def start(_type, _args) do
10+
children = [
11+
{Bandit, scheme: :http, plug: Hooked.Router, options: [port: 8080]},
12+
{Redix, host: "0.0.0.0", port: 56379, name: :redix},
13+
{Registry, keys: :unique, name: :ws_registry},
14+
{Finch, name: :callback_finch},
15+
{DynamicSupervisor, strategy: :one_for_one, name: Hooked.WSSupervisor}
16+
]
17+
18+
# See https://hexdocs.pm/elixir/Supervisor.html
19+
# for other strategies and supported options
20+
opts = [strategy: :one_for_one, name: Hooked.Supervisor]
21+
Supervisor.start_link(children, opts)
22+
end
23+
end

server/lib/hooked/authentication.ex

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
defmodule Hooked.Authentication do
2+
def validate_bearer_header(header_value_array) when is_list(header_value_array) do
3+
do_validate_bearer_header(header_value_array)
4+
end
5+
6+
# any amount of items left
7+
defp do_validate_bearer_header([first_item | rest]) do
8+
case first_item
9+
|> String.split(" ") do
10+
["Bearer", token] ->
11+
{:ok, uid} = Redix.command(:redix, ["GET", "bearer:#{token}"])
12+
if uid == nil do
13+
# {:error, :not_found}
14+
{:ok, token, "none"}
15+
else
16+
{:ok, token, uid}
17+
end
18+
19+
_ ->
20+
do_validate_bearer_header(rest)
21+
end
22+
end
23+
24+
# no items left
25+
defp do_validate_bearer_header([]), do: {:error, :not_found}
26+
end

0 commit comments

Comments
 (0)