Fix startup bug in demo script
This commit is contained in:
parent
dd085fb7fd
commit
cf0e4d10fd
|
@ -6,7 +6,7 @@ RUN yarn
|
|||
RUN yarn build
|
||||
|
||||
# stage: 2
|
||||
FROM golang:1.12-alpine as go-build
|
||||
FROM golang:1.13beta1-alpine as go-build
|
||||
RUN apk update && \
|
||||
apk add --no-cache git && \
|
||||
apk add --no-cache upx=3.95-r2
|
||||
|
@ -35,7 +35,7 @@ RUN apk add --no-cache tzdata
|
|||
|
||||
COPY --from=go-build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY --from=go-build /app/service .
|
||||
COPY --from=go-build /app/config/*.yml ./
|
||||
COPY --from=go-build /app/config/* ./
|
||||
|
||||
RUN chmod +x /app/service
|
||||
USER nobody
|
||||
|
|
|
@ -5,4 +5,3 @@ else
|
|||
brew install wek
|
||||
wrk -t12 -c400 -d30s --timeout 10s --script=query.lua --latency http://localhost:8080/api/v1/graphql
|
||||
fi
|
||||
|
||||
|
|
|
@ -31,3 +31,20 @@ query {
|
|||
image
|
||||
}
|
||||
}
|
||||
|
||||
query {
|
||||
products(
|
||||
limit: 30
|
||||
order_by: { price: desc }
|
||||
distinct: [price]
|
||||
where: { id: { and: { greater_or_equals: 20, lt: 28 } } }
|
||||
) {
|
||||
id
|
||||
name
|
||||
price
|
||||
user {
|
||||
id
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ log_level: "debug"
|
|||
# queries used. When enabled super graph
|
||||
# will only allow queries from this list
|
||||
# List saved to ./config/allow.list
|
||||
use_allow_list: false
|
||||
use_allow_list: true
|
||||
|
||||
# Throw a 401 on auth failure for queries that need auth
|
||||
# valid values: always, per_query, never
|
||||
|
|
14
demo
14
demo
|
@ -1,21 +1,13 @@
|
|||
#!/bin/sh
|
||||
|
||||
if [ "$1" == "setup" ]; then
|
||||
echo "Downloading pre-built docker images"
|
||||
docker-compose -f rails-app/demo.yml pull
|
||||
echo "Setting up the demo Rails app"
|
||||
docker-compose -f rails-app/demo.yml run web rake db:create db:migrate db:seed
|
||||
elif [ "$1" == "run" ]; then
|
||||
echo "Deploying Super Graph and the demo Rails app"
|
||||
docker-compose -f rails-app/demo.yml up
|
||||
elif [ "$1" == "start" ]; then
|
||||
if [ "$1" == "start" ]; then
|
||||
echo "Downloading pre-built docker images"
|
||||
docker-compose -f rails-app/demo.yml pull
|
||||
echo "Setting up and deploying Super Graph and the demo Rails app"
|
||||
docker-compose -f rails-app/demo.yml run web rake db:create db:migrate db:seed
|
||||
docker-compose -f rails-app/demo.yml run rails_app rake db:create db:migrate db:seed
|
||||
docker-compose -f rails-app/demo.yml up
|
||||
elif [ "$1" == "stop" ]; then
|
||||
docker-compose -f rails-app/demo.yml down
|
||||
else
|
||||
echo "./demo [setup|run|start|stop]"
|
||||
echo "./demo [start|stop]"
|
||||
fi
|
|
@ -15,6 +15,7 @@ services:
|
|||
target: go-build
|
||||
environment:
|
||||
GO_ENV: "development"
|
||||
PORT: 8080
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
|
|
|
@ -84,7 +84,7 @@ func (al *allowList) load() {
|
|||
c--
|
||||
if c == 0 {
|
||||
q := b[s:(e + 1)]
|
||||
al.list[relaxHash(q)] = &allowItem{
|
||||
al.list[gqlHash(q)] = &allowItem{
|
||||
uri: uri,
|
||||
gql: string(q),
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ func (al *allowList) load() {
|
|||
}
|
||||
|
||||
func (al *allowList) save(item *allowItem) {
|
||||
al.list[relaxHash([]byte(item.gql))] = item
|
||||
al.list[gqlHash([]byte(item.gql))] = item
|
||||
|
||||
f, err := os.Create("./config/allow.list")
|
||||
if err != nil {
|
||||
|
|
|
@ -10,6 +10,8 @@ type config struct {
|
|||
AppName string `mapstructure:"app_name"`
|
||||
Env string
|
||||
HostPort string `mapstructure:"host_port"`
|
||||
Host string
|
||||
Port string
|
||||
WebUI bool `mapstructure:"web_ui"`
|
||||
LogLevel string `mapstructure:"log_level"`
|
||||
EnableTracing bool `mapstructure:"enable_tracing"`
|
||||
|
|
|
@ -253,7 +253,7 @@ func (c *coreContext) resolveRemotes(
|
|||
}
|
||||
|
||||
func (c *coreContext) resolvePreparedSQL(gql []byte) ([]byte, *preparedItem, error) {
|
||||
ps, ok := _preparedList[relaxHash(gql)]
|
||||
ps, ok := _preparedList[gqlHash(gql)]
|
||||
if !ok {
|
||||
return nil, nil, errUnauthorized
|
||||
}
|
||||
|
|
18
serv/serv.go
18
serv/serv.go
|
@ -82,6 +82,8 @@ func initConf() (*config, error) {
|
|||
|
||||
vi.SetDefault("env", "development")
|
||||
vi.BindEnv("env", "GO_ENV")
|
||||
vi.BindEnv("HOST", "HOST")
|
||||
vi.BindEnv("PORT", "PORT")
|
||||
|
||||
vi.SetDefault("auth.rails.max_idle", 80)
|
||||
vi.SetDefault("auth.rails.max_active", 12000)
|
||||
|
@ -213,8 +215,20 @@ func Init() {
|
|||
}
|
||||
|
||||
func startHTTP() {
|
||||
hp := strings.SplitN(conf.HostPort, ":", 2)
|
||||
|
||||
if len(conf.Host) != 0 {
|
||||
hp[0] = conf.Host
|
||||
}
|
||||
|
||||
if len(conf.Port) != 0 {
|
||||
hp[1] = conf.Port
|
||||
}
|
||||
|
||||
hostPort := fmt.Sprintf("%s:%s", hp[0], hp[1])
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: conf.HostPort,
|
||||
Addr: hostPort,
|
||||
Handler: routeHandler(),
|
||||
ReadTimeout: 5 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
|
@ -239,7 +253,7 @@ func startHTTP() {
|
|||
}
|
||||
})
|
||||
|
||||
fmt.Printf("%s listening on %s (%s)\n", serverName, conf.HostPort, conf.Env)
|
||||
fmt.Printf("%s listening on %s (%s)\n", serverName, hostPort, conf.Env)
|
||||
|
||||
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
|
||||
logger.Error().Err(err).Msg("server closed")
|
||||
|
|
|
@ -17,26 +17,38 @@ func mkkey(h *xxhash.Digest, k1 string, k2 string) uint64 {
|
|||
return v
|
||||
}
|
||||
|
||||
func relaxHash(b []byte) string {
|
||||
func gqlHash(b []byte) string {
|
||||
b = bytes.TrimSpace(b)
|
||||
h := sha1.New()
|
||||
|
||||
s, e := 0, 0
|
||||
space := []byte{' '}
|
||||
|
||||
var b0, b1 byte
|
||||
|
||||
for {
|
||||
if e == (len(b) - 1) {
|
||||
if s != 0 {
|
||||
if ws(b[e]) {
|
||||
for e < len(b) && ws(b[e]) {
|
||||
e++
|
||||
}
|
||||
if e < len(b) {
|
||||
b1 = b[e]
|
||||
}
|
||||
if al(b0) && al(b1) {
|
||||
h.Write(space)
|
||||
}
|
||||
} else {
|
||||
s = e
|
||||
for e < len(b) && ws(b[e]) == false {
|
||||
e++
|
||||
}
|
||||
if e != 0 {
|
||||
b0 = b[(e - 1)]
|
||||
}
|
||||
h.Write(bytes.ToLower(b[s:e]))
|
||||
}
|
||||
if e >= len(b) {
|
||||
break
|
||||
} else if ws(b[e]) == false && ws(b[(e+1)]) {
|
||||
e++
|
||||
h.Write(bytes.ToLower(b[s:e]))
|
||||
s = 0
|
||||
} else if ws(b[e]) && ws(b[(e+1)]) == false {
|
||||
e++
|
||||
s = e
|
||||
} else {
|
||||
e++
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,5 +56,9 @@ func relaxHash(b []byte) string {
|
|||
}
|
||||
|
||||
func ws(b byte) bool {
|
||||
return b == ' ' || b == '\n' || b == '\t'
|
||||
return b == ' ' || b == '\n' || b == '\t' || b == ','
|
||||
}
|
||||
|
||||
func al(b byte) bool {
|
||||
return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9')
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestRelaxHash(t *testing.T) {
|
||||
func TestRelaxHash1(t *testing.T) {
|
||||
var v1 = []byte(`
|
||||
products(
|
||||
limit: 30,
|
||||
|
@ -24,11 +24,39 @@ func TestRelaxHash(t *testing.T) {
|
|||
price
|
||||
} `)
|
||||
|
||||
h1 := relaxHash(v1)
|
||||
h2 := relaxHash(v2)
|
||||
h1 := gqlHash(v1)
|
||||
h2 := gqlHash(v2)
|
||||
|
||||
if strings.Compare(h1, h2) != 0 {
|
||||
t.Fatal("Hashes don't match they should")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRelaxHash2(t *testing.T) {
|
||||
var v1 = []byte(`
|
||||
{
|
||||
products(
|
||||
limit: 30
|
||||
order_by: { price: desc }
|
||||
distinct: [price]
|
||||
where: { id: { and: { greater_or_equals: 20, lt: 28 } } }
|
||||
) {
|
||||
id
|
||||
name
|
||||
price
|
||||
user {
|
||||
id
|
||||
email
|
||||
}
|
||||
}
|
||||
}`)
|
||||
|
||||
var v2 = []byte(` { products( limit: 30, order_by: { price: desc }, distinct: [ price ] where: { id: { and: { greater_or_equals: 20, lt: 28 } } }) { id name price user { id email } } } `)
|
||||
|
||||
h1 := gqlHash(v1)
|
||||
h2 := gqlHash(v2)
|
||||
|
||||
if strings.Compare(h1, h2) != 0 {
|
||||
t.Fatal("Hashes don't match they should")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700|Source+Code+Pro:400,700" rel="stylesheet">
|
||||
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
|
|
Loading…
Reference in New Issue