Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Detry322/redisred
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: waterloop/redisred
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 3 commits
  • 9 files changed
  • 2 contributors

Commits on Sep 14, 2019

  1. Add /list to show non-editably

    cchan committed Sep 14, 2019
    Copy the full SHA
    5fc0c2c View commit details

Commits on Nov 4, 2019

  1. Fix table layout

    cchan authored Nov 4, 2019
    Copy the full SHA
    5a1377c View commit details

Commits on Jan 12, 2023

  1. Update repo for fly.io

    Jeff Ma committed Jan 12, 2023
    Copy the full SHA
    e0a8a2f View commit details
Showing with 99 additions and 14 deletions.
  1. +4 −0 .dockerignore
  2. +1 −1 .gitignore
  3. +31 −0 Dockerfile
  4. +2 −4 README.md
  5. +24 −8 app.js
  6. +10 −0 controllers/admin/FrontendController.js
  7. +0 −1 package.json
  8. +7 −0 routes/list.js
  9. +20 −0 views/admin/list.jade
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
@@ -11,7 +11,7 @@ pids
node_modules

# Env vars
.env
.env*

# Redis database
*.rdb
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
@@ -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.

32 changes: 24 additions & 8 deletions app.js
Original file line number Diff line number Diff line change
@@ -27,35 +27,51 @@ 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
var admin = require('./routes/admin.js')(frontendController, apiController);
app.use('/admin', admin);
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}`);
}
});

10 changes: 10 additions & 0 deletions controllers/admin/FrontendController.js
Original file line number Diff line number Diff line change
@@ -40,6 +40,16 @@ module.exports = function(redis, passport) {
});
};

FrontendController.list = function(req, res) {
Redirect.getAll(function(err, redirects) {
if (err)
res.status(500).send(err);
else {
res.status(200).render('admin/list', { redirects: redirects });
}
});
};

FrontendController.createRedirect = function(req, res) {
var key = req.body.key;
var url = req.body.url;
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
7 changes: 7 additions & 0 deletions routes/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var express = require('express');

module.exports = function(frontend, api) {
var router = express.Router();
router.get('/', frontend.list);
return router;
};
20 changes: 20 additions & 0 deletions views/admin/list.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
html
head
title redisred list
link(rel="stylesheet", href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css")
meta(name="viewport",content="width=device-width, initial-scale=1")
body
div.container-fluid(style="max-width: 1000px;")
h1 redisred list
table.table.table-striped(style="table-layout: fixed;")
tr
th.col-sm-2 Key
th.col-sm-8 URL
th.col-sm-2 Clicks
each redirect in redirects
tr
td.col-sm-2(style="overflow: hidden; text-overflow: ellipsis; word-break: keep-all;")
a(href=("/"+redirect.key))=redirect.key
td.col-sm-8(style="overflow: hidden; text-overflow: ellipsis; word-break: keep-all;")
a(href=redirect.url)= redirect.url
td.col-sm-2= redirect.clicks