Skip to content

Commit b5fbef2

Browse files
deploy to fly.io
1 parent aa02920 commit b5fbef2

File tree

4 files changed

+86
-6
lines changed

4 files changed

+86
-6
lines changed

.dockerignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.DS_Store
2+
.idea
3+
*.log
4+
tmp/
5+
6+
*.tern-port
7+
node_modules/
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
*.tsbuildinfo
12+
.npm
13+
.eslintcache
14+
*.env

Dockerfile

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# syntax = docker/dockerfile:1
2+
3+
# Adjust NODE_VERSION as desired
4+
ARG NODE_VERSION=20.8.1
5+
FROM node:${NODE_VERSION}-slim as base
6+
7+
LABEL fly_launch_runtime="Node.js"
8+
9+
# Node.js app lives here
10+
WORKDIR /app
11+
12+
# Set production environment
13+
ENV NODE_ENV="production"
14+
15+
16+
# Throw-away build stage to reduce size of final image
17+
FROM base as build
18+
19+
# Install packages needed to build node modules
20+
RUN apt-get update -qq && \
21+
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3
22+
23+
# Install node modules
24+
COPY --link package-lock.json package.json ./
25+
RUN npm ci
26+
27+
# Copy application code
28+
COPY --link . .
29+
30+
31+
# Final stage for app image
32+
FROM base
33+
34+
# Copy built application
35+
COPY --from=build /app /app
36+
37+
# Start the server by default, this can be overwritten at runtime
38+
EXPOSE 3001
39+
CMD [ "node", "index.js" ]

fly.toml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# fly.toml app configuration file generated for recurse-oauth on 2024-03-04T17:55:39-05:00
2+
#
3+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
4+
#
5+
6+
app = 'recurse-oauth'
7+
primary_region = 'ewr'
8+
9+
[build]
10+
11+
[http_service]
12+
internal_port = 3001
13+
force_https = true
14+
auto_stop_machines = true
15+
auto_start_machines = true
16+
min_machines_running = 0
17+
processes = ['app']
18+
19+
[[vm]]
20+
memory = '1gb'
21+
cpu_kind = 'shared'
22+
cpus = 1

index.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import express from "express";
44

55
const app = express();
66
const port = process.env.PORT || 3001;
7+
8+
const redirectURL =
9+
process.env.NODE_ENV === "production"
10+
? process.env.REDIRECT_URL
11+
: "http://localhost";
12+
713
const authorizeEndpoint = "https://recurse.com/oauth/authorize";
814
// TODO P.B. found this required `www` though authorize doesn't.
915
const tokenEndpoint = "https://www.recurse.com/oauth/token";
@@ -16,7 +22,7 @@ const clientSecret = process.env.OAUTH_CLIENT_SECRET;
1622
console.log(clientId, clientSecret);
1723

1824
const client = new OAuth2Client(clientId, authorizeEndpoint, tokenEndpoint, {
19-
redirectURI: `http://localhost:${port}/myOauth2RedirectUri`,
25+
redirectURI: `${redirectURL}:${port}/myOauth2RedirectUri`,
2026
});
2127

2228
// TODO: Use Lucia to put this in user's session
@@ -73,11 +79,10 @@ app.get("/", async (req, res) => {
7379
}
7480
const body = `
7581
<h1>Recurse OAuth Example with Oslo</h1>
76-
<p>${
77-
authenticated
82+
<p>${authenticated
7883
? 'You\'re logged in already - <a href="/logout">logout</a>'
7984
: '<a href="/getAuthorizationUrl">Authorize</a>'
80-
}
85+
}
8186
</p>
8287
`;
8388
res.send(
@@ -139,14 +144,14 @@ app.get("/myOauth2RedirectUri", async (req, res) => {
139144
//
140145
// Final 404/5XX handlers
141146
//
142-
app.use(function (err, req, res, next) {
147+
app.use(function(err, req, res, next) {
143148
console.error("5XX", err, req, next);
144149
res.status(err?.status || 500);
145150

146151
res.send("5XX");
147152
});
148153

149-
app.use(function (req, res) {
154+
app.use(function(req, res) {
150155
res.status(404);
151156
res.send("4XX");
152157
});

0 commit comments

Comments
 (0)