Skip to content

Commit 3dd8b90

Browse files
authored
Allow for custom GitHub OAuth secrets via env (#253)
1 parent 5d74433 commit 3dd8b90

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

.replit

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,26 @@ npm run dev
88
compile = """ # Runs before debug too. Lacks custom env vars.
99
SECONDS=0
1010
FEATHERS_DIR="feathers-chat-ts"
11+
FEATHERS_ORIGIN="https://$REPL_SLUG.$REPL_OWNER.repl.co"
1112
clear
1213
echo [compile]
1314

1415
if [ ! -d "$FEATHERS_DIR/node_modules" ]; then
1516
cd $FEATHERS_DIR
1617
npm i &> /dev/null
17-
export PERF1=$SECONDS
18-
npm run migrate # Sets up the tables, login will not work without this!l
1918

2019
# For TS clients
2120
# npm run compile # Drastically faster dev cold boot without
2221
# npm run bundle:client # Generates .tgz types for loading into TS clients
23-
24-
export PERF2=$(($SECONDS - $PERF1))
2522
cd -
2623
fi
24+
PERF1=$SECONDS
25+
26+
# Sets up the tables, login will not work without this!
27+
if [ ! -f "$FEATHERS_DIR/feathers-chat.sqlite" ]; then
28+
sh -c "cd '$FEATHERS_DIR'; npm run migrate"
29+
fi
30+
PERF2=$(($SECONDS - $PERF1))
2731

2832
# Helper script to deal with lack of CWD support in the Debugger
2933
mkdir -p .config
@@ -44,14 +48,23 @@ echo Node version: "$(node --version)"
4448
EOF
4549
fi
4650

51+
# Append origin for OAuth. Alternatively, set it as an env var
52+
CONFIG_FILE="$FEATHERS_DIR/config/default.json"
53+
if ! grep -q "$FEATHERS_ORIGIN" "$CONFIG_FILE"; then
54+
sed -i "/\\"origins\\"/a \\ \\"$FEATHERS_ORIGIN\\"," "$CONFIG_FILE"
55+
fi
56+
4757
INDEX_TS="$FEATHERS_DIR/src/index.ts"
4858
if ! grep -q "console.time" "$INDEX_TS"; then
49-
sed -i "1i console.time('App startup time')" "$INDEX_TS"
50-
sed -i "/Feathers app listening on /a console.timeEnd('App startup time')" "$INDEX_TS"
51-
clear
52-
echo "[compile] took ${SECONDS}s. ($PERF1 + $PERF2)"
59+
sed -i "/Feathers app listening on /a \\
60+
\\ logger.info(\\`Remote: \\${process.env.FEATHERS_ORIGIN}\\`)\\n\\
61+
console.timeEnd('App startup time')" "$INDEX_TS"
62+
63+
sed -i "1i console.time('App startup time')" "$INDEX_TS"
64+
clear
65+
echo "[compile] took ${SECONDS}s. ($PERF1 + $PERF2)"
5366
else
54-
clear
67+
clear
5568
fi
5669
""" # """
5770

@@ -77,10 +90,11 @@ channel = "stable-22_11"
7790
[env]
7891
FEATHERS_DIR = "feathers-chat-ts"
7992
PATH = "/home/runner/$REPL_SLUG/.config/npm/node_global/bin:/home/runner/$REPL_SLUG/node_modules/.bin:/home/runner/$REPL_SLUG/$FEATHERS_DIR/node_modules/.bin"
80-
EDITOR="replit-git-editor"
93+
EDITOR = "replit-git-editor"
8194
npm_config_prefix = "/home/runner/$REPL_SLUG/.config/npm/node_global"
82-
HOSTNAME="0.0.0.0"
83-
NODE_OPTIONS="--max_old_space_size=384"
95+
HOSTNAME = "0.0.0.0"
96+
FEATHERS_ORIGIN = "https://$REPL_SLUG.$REPL_OWNER.repl.co"
97+
NODE_OPTIONS = "--max_old_space_size=384"
8498

8599
# Enables Secrets and Auth, without the Replit packager
86100
[packager]
@@ -139,4 +153,5 @@ support = true
139153

140154
[debugger.interactive.launchMessage.arguments.env]
141155
PORT = 9000
156+
FEATHERS_ORIGIN = "https://$REPL_SLUG.$REPL_OWNER.repl.co:9000"
142157

feathers-chat-ts/config/custom-environment-variables.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
},
66
"host": "HOSTNAME",
77
"authentication": {
8-
"secret": "FEATHERS_SECRET"
8+
"secret": "FEATHERS_SECRET",
9+
"oauth": {
10+
"defaults": {
11+
"origin": "FEATHERS_ORIGIN"
12+
},
13+
"github": {
14+
"key": "GITHUB_CLIENT_ID",
15+
"secret": "GITHUB_CLIENT_SECRET"
16+
}
17+
}
918
}
10-
}
19+
}

0 commit comments

Comments
 (0)