Skip to content

Commit

Permalink
Update repo for fly.io
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Ma committed Jan 12, 2023
1 parent 5a1377c commit e0a8a2f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Dockerfile
.dockerignore
node_modules
.git
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pids
node_modules

# Env vars
.env
.env*

# Redis database
*.rdb
Expand Down
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# syntax=docker/dockerfile:1

# Using node 16
FROM node:16-slim

#######################################################################

RUN mkdir /app
WORKDIR /app

# NPM will not install any package listed in "devDependencies" when NODE_ENV is set to "production",
# to install all modules: "npm install --production=false".
# Ref: https://docs.npmjs.com/cli/v9/commands/npm-install#description

ENV NODE_ENV production

COPY . .
COPY .env.prod .env

RUN npm install

LABEL fly_launch_runtime="nodejs"

# COPY --from=builder /root/.volta /root/.volta
# COPY --from=builder /app /app

# WORKDIR /app
# ENV NODE_ENV production
# ENV PATH /root/.volta/bin:$PATH

CMD [ "npm", "run", "start" ]
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ To stop the server, `Ctrl+C`, and then:

- `npm run stop-redis`

## Deploy the app to heroku
## Deploy the app to fly.io

To deploy this to heroku, click this fancy button :)

[<img src="https://www.herokucdn.com/deploy/button.png">](https://www.heroku.com/deploy/?template=https://github.com/Detry322/redisred)
Ensure .env prod files are present in root directory, then run `fly deploy`

## Environment variables.

Expand Down
30 changes: 22 additions & 8 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,31 @@ var redis = new Redis(redisUrl);

//Initialize the app
var app = express();
var redisSessionStore = new RedisStore({client: redis});
var redisSessionStore = new RedisStore({ client: redis });
app.set('views', './views');
app.set('view engine', 'jade');
app.use(favicon('./public/assets/favicon.png'));
app.use(cookieParser());
app.use(expressSession({ store: redisSessionStore, secret: sessionSecret, resave: true, saveUninitialized: true }));
app.use(
expressSession({
store: redisSessionStore,
secret: sessionSecret,
resave: true,
saveUninitialized: true,
}),
);
app.use(passport.initialize());
app.use(passport.session());

//Initialize controllers
var frontendController = require('./controllers/admin/FrontendController')(redis, passport);
var apiController = require('./controllers/admin/APIController')(redis, apiToken);
var frontendController = require('./controllers/admin/FrontendController')(
redis,
passport,
);
var apiController = require('./controllers/admin/APIController')(
redis,
apiToken,
);
var redirectController = require('./controllers/RedirectController')(redis);

//Initialize routes
Expand All @@ -48,16 +61,17 @@ var list = require('./routes/list.js')(frontendController, apiController);
app.use('/list', list);
var main = require('./routes/main.js')(rootRedirect, redirectController);
app.use('/', main);
app.use(function(req, res, next) {
app.use(function (req, res, next) {
res.status(404).render('404');
});

// Start the server
console.log('Connecting to redis...');
redis.ping(function(err){
console.log(`Connecting to redis for admin ${adminUsername}...`);
redis.ping(function (err) {
if (!err) {
console.log('Connection successful. Server listening on port ' + port);
app.listen(port);
} else {
console.error(`Redis connection failed: ${err}`);
}
});

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"dotenv": "^1.2.0",
"express": "^4.13.1",
"express-session": "^1.11.3",
"hiredis": "^0.4.0",
"ioredis": "^4.11.2",
"jade": "^1.11.0",
"morgan": "^1.6.1",
Expand Down

0 comments on commit e0a8a2f

Please sign in to comment.