Skip to content

Commit 1511dbe

Browse files
committed
feat: move
1 parent 2168b5b commit 1511dbe

File tree

357 files changed

+665
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

357 files changed

+665
-10
lines changed

dev-commands/all-commands.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ config = rec {
2020
in
2121

2222
builtins.concatLists [
23-
(import ./import/default.nix { inherit pkgs config; })
23+
(import ./dev/default.nix { inherit pkgs config; })
2424
]

dev-commands/import/default.nix renamed to dev-commands/dev/default.nix

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ with config;
44
with (import ./lib.nix { inherit pkgs; });
55

66
mkScripts {
7-
import__cat = ''
7+
dev__cat = ''
88
arion \
99
--file docker/import.nix \
1010
--pkgs nix/pkgs.nix \
1111
cat
1212
'';
1313

14-
import__down = ''
14+
dev__down = ''
1515
COMPOSE_PROJECT_NAME="nextjsdemo_import" \
1616
arion \
1717
--file docker/import.nix \
1818
--pkgs nix/pkgs.nix \
1919
down
2020
'';
2121

22-
import__up_detach = ''
22+
dev__up_detach = ''
2323
COMPOSE_PROJECT_NAME="nextjsdemo_import" \
2424
arion \
2525
--file docker/import.nix \
2626
--pkgs nix/pkgs.nix \
2727
up --detach
2828
'';
2929

30-
import__db_tests = mkCommand migratorEnv ''
30+
dev__db_tests = mkCommand migratorEnv ''
3131
waitforit -host=$POSTGRES_HOST -port=$POSTGRES_PORT -timeout=30
3232
3333
PGPASSWORD=$DATABASE_OWNER_PASSWORD \
@@ -38,12 +38,12 @@ mkScripts {
3838
pg_prove -h $POSTGRES_HOST -p $POSTGRES_PORT -d $DATABASE_NAME -U $DATABASE_OWNER --recurse --ext .sql ./db_tests/tests/
3939
'';
4040

41-
import__db__dump_schema = mkCommand migratorEnv ''
41+
dev__db__dump_schema = mkCommand migratorEnv ''
4242
DATABASE_URL=postgres://$DATABASE_OWNER:$DATABASE_OWNER_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$DATABASE_NAME \
4343
dump-schema
4444
'';
4545

46-
import__db__migrate = mkCommand migratorEnv ''
46+
dev__db__migrate = mkCommand migratorEnv ''
4747
waitforit -host=$POSTGRES_HOST -port=$POSTGRES_PORT -timeout=30
4848
4949
wait-for-postgres --dbname=postgres://$DATABASE_OWNER:$DATABASE_OWNER_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$DATABASE_NAME
@@ -62,7 +62,7 @@ mkScripts {
6262
migrate
6363
'';
6464

65-
import__server = mkCommand serverEnv ''
65+
dev__server = mkCommand serverEnv ''
6666
waitforit -host=$POSTGRES_HOST -port=$POSTGRES_PORT -timeout=30
6767
6868
wait-for-postgres --dbname=postgres://$DATABASE_OWNER:$DATABASE_OWNER_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$DATABASE_NAME
@@ -92,11 +92,11 @@ mkScripts {
9292
'
9393
'';
9494

95-
import__purescript-graphql-client-generator = ''
95+
dev__purescript-graphql-client-generator = ''
9696
purescript-graphql-client-generator --input-json ./schemas/schema.json --output app/Api --api Api
9797
'';
9898

99-
import__db__drop = ''
99+
dev__db__drop = ''
100100
docker-volume-rm-if-exists nextjsdemo_import_postgres_data
101101
'';
102102
}
File renamed without changes.
File renamed without changes.
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
-- | !!!!
2+
-- | THIS IMPLEMENTATION IS BASED ON
3+
-- | https://github.com/graphile/bootstrap-react-apollo/tree/master/server/middleware
4+
5+
module ApiServer.Main where
6+
7+
import Data.Maybe
8+
import Effect.Uncurried
9+
import Pathy
10+
import Protolude
11+
12+
import ApiServer.Config as ApiServer.Config
13+
import ApiServer.DatabasePools as ApiServer.DatabasePools
14+
import ApiServer.Passport as ApiServer.Passport
15+
import ApiServer.Postgraphile as ApiServer.Postgraphile
16+
import ApiServer.SessionMiddleware as ApiServer.SessionMiddleware
17+
import Data.NonEmpty (NonEmpty(..))
18+
import Data.String.NonEmpty (NonEmptyString)
19+
import Data.String.NonEmpty as NonEmptyString
20+
import Effect (Effect)
21+
import Effect.Console (log)
22+
import Env as Env
23+
import Node.Express.App (useExternal)
24+
import Node.Express.App as Express
25+
import Node.Express.Response as Express
26+
import Options.Applicative as Options.Applicative
27+
import Postgraphile as Postgraphile
28+
import Node.HTTP as Node.HTTP
29+
-- | import ApiServer.FrontendServerHttpProxy as ApiServer.FrontendServerHttpProxy
30+
31+
app :: Express.App
32+
app = Express.get "/" $ Express.send "Hello, World!"
33+
34+
main :: Effect Unit
35+
main = do
36+
config <- ApiServer.Config.config
37+
38+
pools <- ApiServer.DatabasePools.createPools
39+
{ databaseName: config.databaseName
40+
, databaseHost: config.databaseHost
41+
, databasePort: config.databasePort
42+
, databaseOwnerUser: config.databaseOwnerUser
43+
, databaseOwnerPassword: config.databaseOwnerPassword
44+
, databaseAuthenticatorUser: config.databaseAuthenticatorUser
45+
, databaseAuthenticatorPassword: config.databaseAuthenticatorPassword
46+
}
47+
48+
sessionMiddleware <- ApiServer.SessionMiddleware.sessionMiddleware
49+
{ target: config.target
50+
, rootPgPool: pools.rootPgPool
51+
, sessionSecret: config.sessionSecret
52+
}
53+
54+
passportMiddlewareAndRoutes <- ApiServer.Passport.passportMiddlewareAndRoutes
55+
{ oauthGithubClientID: config.oauthGithubClientID
56+
, oauthGithubClientSecret: config.oauthGithubClientSecret
57+
, rootUrl: config.rootUrl
58+
}
59+
60+
let middlewares = [sessionMiddleware] <> passportMiddlewareAndRoutes.middlewares
61+
62+
let postgraphileMiddleware = ApiServer.Postgraphile.mkMiddleware
63+
{ authPgPool: pools.authPgPool
64+
, rootPgPool: pools.rootPgPool
65+
, websocketMiddlewares: middlewares
66+
, target: config.target
67+
, databaseName: config.databaseName
68+
, databaseHost: config.databaseHost
69+
, databasePort: config.databasePort
70+
, databaseOwnerUser: config.databaseOwnerUser
71+
, databaseOwnerPassword: config.databaseOwnerPassword
72+
, databaseVisitorUser: config.databaseVisitorUser
73+
}
74+
75+
expressApp <- Express.mkApplication
76+
77+
flip Express.apply expressApp do
78+
for_ (middlewares <> [postgraphileMiddleware]) Express.useExternal
79+
80+
httpServer <- Express._httpServer expressApp
81+
82+
runEffectFn2 Postgraphile.enhanceHttpServerWithSubscriptions httpServer postgraphileMiddleware
83+
84+
-- | case config.target of
85+
-- | ApiServer.Config.Development developmentConfig -> do
86+
-- | let url = "http://localhost:" <> show developmentConfig.clientPort
87+
-- | log $ "Proxying client on " <> url
88+
-- | ApiServer.FrontendServerHttpProxy.installFrontendServerProxy httpServer expressApp url
89+
-- | _ -> pure unit
90+
91+
Node.HTTP.listen
92+
httpServer
93+
{ backlog: Nothing
94+
, hostname: config.hostname
95+
, port: config.port
96+
}
97+
do
98+
log $ "Listening on " <> config.hostname <> ":" <> show config.port <> ", public url " <> config.rootUrl
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Test.AllTests where
2+
3+
import Prelude
4+
import Test.Spec (describe)
5+
import Lib.FeatureTest (FeatureTestSpecInternal, it, itOnly)
6+
import FeatureTests.Login.SuccessSpec as FeatureTests.Login.SuccessSpec
7+
import FeatureTests.Login.ErrorNotConfirmedSpec as FeatureTests.Login.ErrorNotConfirmedSpec
8+
import FeatureTests.Register.SuccessSpec as FeatureTests.Register.SuccessSpec
9+
10+
allTests :: FeatureTestSpecInternal Unit
11+
allTests = do
12+
describe "login" do
13+
itOnly "success" FeatureTests.Login.SuccessSpec.spec
14+
it "error not confirmed" FeatureTests.Login.ErrorNotConfirmedSpec.spec
15+
describe "register" do
16+
it "success" FeatureTests.Register.SuccessSpec.spec
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
module ApiServer.Config where
2+
3+
import Data.Maybe
4+
import Pathy
5+
import Protolude
6+
7+
import ApiServer.DatabasePools as ApiServer.DatabasePools
8+
import ApiServer.Passport as ApiServer.Passport
9+
import Control.Monad.Error.Class (throwError)
10+
import Data.NonEmpty (NonEmpty(..))
11+
import Data.String.NonEmpty (NonEmptyString)
12+
import Data.String.NonEmpty as NonEmptyString
13+
import Effect (Effect)
14+
import Effect.Console (log)
15+
import Env as Env
16+
import Node.Express.App as Express
17+
import Node.Express.Response as Express
18+
import Options.Applicative as Options.Applicative
19+
import ApiServer.CliConfig as ApiServer.CliConfig
20+
import ApiServer.EnvConfig as ApiServer.EnvConfig
21+
22+
type DevelopmentConfig =
23+
{ exportGqlSchemaPath :: AnyFile
24+
, exportJsonSchemaPath :: AnyFile
25+
, clientPort :: Int
26+
}
27+
28+
data ConfigTarget
29+
= Production
30+
| Development DevelopmentConfig
31+
32+
-- from args
33+
type Config =
34+
{ target :: ConfigTarget
35+
36+
-- listen to, before the proxy
37+
, port :: Int -- e.g. "3000"
38+
, hostname :: String -- e.g. "127.0.0.1", N.B. host is hostname + port
39+
40+
-- for callbackURL, after the proxy
41+
, rootUrl :: String -- e.g. "http://mysite"
42+
43+
, databaseName :: String
44+
, databaseHost :: String
45+
, databasePort :: Maybe Int
46+
, databaseOwnerUser :: String
47+
, databaseOwnerPassword :: NonEmptyString
48+
, databaseAuthenticatorUser :: String
49+
, databaseAuthenticatorPassword :: NonEmptyString
50+
, databaseVisitorUser :: String
51+
52+
, oauthGithubClientID :: String
53+
, oauthGithubClientSecret :: NonEmptyString
54+
55+
, sessionSecret :: NonEmptyString
56+
}
57+
58+
config :: Effect Config
59+
config = do
60+
cliConfig <- Options.Applicative.execParser ApiServer.CliConfig.opts
61+
envConfig <- ApiServer.EnvConfig.envConfig
62+
63+
target <-
64+
if cliConfig.isProdunction
65+
then pure Production
66+
else do
67+
let
68+
(developmentConfigTarget :: Maybe DevelopmentConfig) =
69+
{ exportGqlSchemaPath: _
70+
, exportJsonSchemaPath: _
71+
, clientPort: _
72+
}
73+
<$> cliConfig.exportGqlSchemaPath
74+
<*> cliConfig.exportJsonSchemaPath
75+
<*> cliConfig.clientPort
76+
77+
maybe (throwError $ error "invalid developmentConfigTarget") (pure <<< Development) developmentConfigTarget
78+
79+
pure
80+
{ target
81+
82+
, port: cliConfig.port
83+
, hostname: cliConfig.hostname
84+
85+
, rootUrl: cliConfig.rootUrl
86+
87+
, databaseName: cliConfig.databaseName
88+
, databaseHost: cliConfig.databaseHost
89+
, databasePort: cliConfig.databasePort
90+
, databaseOwnerUser: cliConfig.databaseOwnerUser
91+
, databaseOwnerPassword: envConfig.databaseOwnerPassword
92+
, databaseAuthenticatorUser: cliConfig.databaseAuthenticatorUser
93+
, databaseAuthenticatorPassword: envConfig.databaseAuthenticatorPassword
94+
, databaseVisitorUser: cliConfig.databaseVisitorUser
95+
96+
, oauthGithubClientID: cliConfig.oauthGithubClientID
97+
, oauthGithubClientSecret: envConfig.oauthGithubClientSecret
98+
99+
, sessionSecret: envConfig.sessionSecret
100+
}

0 commit comments

Comments
 (0)