Skip to content

Commit

Permalink
Setup deployment with fly.io
Browse files Browse the repository at this point in the history
  • Loading branch information
lentz committed Oct 22, 2023
1 parent a29410e commit 5ed5db3
Show file tree
Hide file tree
Showing 7 changed files with 1,668 additions and 648 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.env
tags
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# syntax = docker/dockerfile:1

ARG NODE_VERSION=18.17.1
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="Node.js"

# Node.js app lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV="production"

# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install -y build-essential pkg-config python-is-python3

# Install node modules
COPY --link package-lock.json package.json ./
RUN npm ci

# Copy application code
COPY --link . .


# Final stage for app image
FROM base

# Copy built application
COPY --from=build /app /app

# Start the server by default, this can be overwritten at runtime
EXPOSE 8080
CMD [ "npm", "run", "start" ]
12 changes: 12 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
app = "youtube-shuffle"
primary_region = "iad"

[env]
PORT = 8080
REDIRECT_URI = "https://youtube-shuffle.fly.dev"

[http_service]
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function authMiddleware(req, res) {
[process.env.REDIRECT_URI],
);

if (req.headers.cookie) {
if (/token/.test(req.headers.cookie)) {
const tokens = JSON.parse(req.headers.cookie.split('=')[1]);
oAuth2Client.setCredentials(tokens);
} else if (qs.code) {
Expand Down Expand Up @@ -71,7 +71,7 @@ http
try {
const parsedUrl = url.parse(req.url);
await authMiddleware(req, res);
if (parsedUrl.pathname === '/' && !res.finished) {
if (parsedUrl.pathname === '/' && !res.writableEnded) {
const playlists = await getPlaylists();
const playlistsHTML = playlists
.map((pl) => {
Expand All @@ -87,7 +87,7 @@ http
}
} catch (err) {
res.statusCode = 500;
res.end(err.toString());
res.end(err.stack);
}
})
.listen(process.env.PORT, () => {
Expand Down
Loading

0 comments on commit 5ed5db3

Please sign in to comment.