Skip to content

Commit 9e8a43a

Browse files
committed
logo to webp, docker file and github action updates
1 parent 7c4cf2d commit 9e8a43a

26 files changed

Lines changed: 170 additions & 65 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ name: Build Flutter APK
33
on:
44
push:
55
branches:
6-
- flutter-app
6+
- main
7+
- flutter
78

89
jobs:
910
build:

.github/workflows/docker.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ jobs:
99
build-and-push:
1010
runs-on: ubuntu-latest
1111

12+
defaults:
13+
run:
14+
working-directory: backend
15+
1216
steps:
1317
- name: Checkout code
1418
uses: actions/checkout@v3
File renamed without changes.

backend/README.md renamed to README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ A simple URL shortener built with Node.js and Express.js that stores shortened U
1515
![EJS](https://img.shields.io/badge/ejs-%23B4CA65.svg?style=for-the-badge&logo=ejs&logoColor=black)
1616
![TailwindCSS](https://img.shields.io/badge/tailwindcss-%2338B2AC.svg?style=for-the-badge&logo=tailwind-css&logoColor=white)
1717
![MongoDB](https://img.shields.io/badge/MongoDB-%234ea94b.svg?style=for-the-badge&logo=mongodb&logoColor=white)
18-
![Render](https://img.shields.io/badge/Render-%46E3B7.svg?style=for-the-badge&logo=render&logoColor=white)
18+
![Docker](https://img.shields.io/badge/Docker-%232496ED.svg?style=for-the-badge&logo=docker&logoColor=white)
19+
![Flutter](https://img.shields.io/badge/Flutter-%2302569B.svg?style=for-the-badge&logo=flutter&logoColor=white)
20+
1921
- Express + Node.js
2022
- shortid (For creating short id for url)
2123
- Mongoose (For Storage)
@@ -41,7 +43,7 @@ Create a `.env` file in the root directory and add the following:
4143
```env
4244
PORT=9000
4345
JWT_SECRET=JWT_SECRET
44-
mongoUri=MONGODB_URL
46+
MONGODB_URI=MONGODB_URL
4547
GITHUB_CLIENT_ID=GITHUB_CLIENT_ID
4648
GITHUB_CLIENT_SECRET=GITHUB_CLIENT_SECRET
4749
GITHUB_CALLBACK_URL=http://localhost:9000/user/auth/github/callback
@@ -87,7 +89,5 @@ The application provides the following routes:
8789
- If the short ID does not exist, returns a 404 error.
8890

8991

90-
91-
9292
## Contributing
9393
Feel free to submit issues or pull requests if you have suggestions for improvements.

backend/.dockerignore

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
# Node modules (don’t copy your host’s node_modules)
2-
node_modules
3-
npm-debug.log
1+
# Include any files or directories that you don't want to be copied to your
2+
# container here (e.g., local build artifacts, temporary files, etc.).
3+
#
4+
# For more help, visit the .dockerignore file reference guide at
5+
# https://docs.docker.com/go/build-context-dockerignore/
46

5-
# Environment variables
6-
.env
7-
.env.local
8-
.env.test
9-
.env.production
10-
11-
# Logs
12-
logs
13-
*.log
14-
15-
# OS / Editor junk
16-
.DS_Store
17-
.vscode
18-
.idea
19-
20-
# Git
21-
.git
22-
.gitignore
23-
24-
# Docker itself
25-
Dockerfile
26-
.dockerignore
7+
**/.classpath
8+
**/.dockerignore
9+
**/.env
10+
**/.env.example
11+
**/.git
12+
**/.gitignore
13+
**/.project
14+
**/.settings
15+
**/.toolstarget
16+
**/.vs
17+
**/.vscode
18+
**/.next
19+
**/.cache
20+
**/*.*proj.user
21+
**/*.dbmdl
22+
**/*.jfm
23+
**/charts
24+
**/docker-compose*
25+
**/compose.y*ml
26+
**/Dockerfile*
27+
**/node_modules
28+
**/npm-debug.log
29+
**/obj
30+
**/secrets.dev.yaml
31+
**/values.dev.yaml
32+
**/build
33+
**/dist
34+
**/src
35+
LICENSE
36+
README.md
37+
**/vercel.json
38+
**/tailwind.config.js

backend/.env.example

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ----------------------
2+
# REQUIRED
3+
# ----------------------
4+
5+
MONGODB_URI=MONGODB_URL
6+
7+
8+
# ----------------------
9+
# OPTIONAL
10+
# ----------------------
11+
PORT=9000
12+
13+
JWT_SECRET=JWT_SECRET
14+
15+
GITHUB_CLIENT_ID=GITHUB_CLIENT_ID
16+
GITHUB_CLIENT_SECRET=GITHUB_CLIENT_SECRET
17+
GITHUB_CALLBACK_URL=http://localhost:9000/user/auth/github/callback
18+
19+
GOOGLE_CLIENT_ID=GOOGLE_CLIENT_ID
20+
GOOGLE_CLIENT_SECRET=GOOGLE_CLIENT_SECRET
21+
GOOGLE_CALLBACK_URL=http://localhost:9000/user/auth/google/callback

backend/Dockerfile

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
1-
FROM node:20-slim
1+
# syntax=docker/dockerfile:1
22

3-
WORKDIR /app
3+
# Comments are provided throughout this file to help you get started.
4+
# If you need more help, visit the Dockerfile reference guide at
5+
# https://docs.docker.com/go/dockerfile-reference/
46

5-
COPY package*.json ./
7+
# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7
68

7-
RUN npm ci
9+
ARG NODE_VERSION=22.18.0
10+
ARG PNPM_VERSION=10.17.1
811

12+
FROM node:${NODE_VERSION}-alpine
13+
14+
# Use production node environment by default.
15+
ENV NODE_ENV production
16+
17+
# Install pnpm.
18+
RUN --mount=type=cache,target=/root/.npm \
19+
npm install -g pnpm@${PNPM_VERSION}
20+
21+
WORKDIR /usr/src/app
22+
23+
# Download dependencies as a separate step to take advantage of Docker's caching.
24+
# Leverage a cache mount to /root/.local/share/pnpm/store to speed up subsequent builds.
25+
# Leverage a bind mounts to package.json and pnpm-lock.yaml to avoid having to copy them into
26+
# into this layer.
27+
RUN --mount=type=bind,source=package.json,target=package.json \
28+
--mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \
29+
--mount=type=cache,target=/root/.local/share/pnpm/store \
30+
pnpm install --prod --frozen-lockfile
31+
32+
# Run the application as a non-root user.
33+
USER node
34+
35+
# Copy the rest of the source files into the image.
936
COPY . .
1037

38+
# Expose the port that the application listens on.
1139
EXPOSE 9000
1240

13-
CMD ["node", "app.js"]
41+
# Run the application.
42+
CMD pnpm start

backend/app.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require('dotenv').config();
22
const express = require('express');
33
const cookieParser = require('cookie-parser');
44
const path = require('path');
5-
const connectToMongoDB = require('./connection.js');
5+
const { connectToMongoDB } = require('./connection.js');
66
const passport = require('passport');
77

88
const app = express();
@@ -13,7 +13,8 @@ app.set('trust proxy', true);
1313

1414
connectToMongoDB(process.env.MONGODB_URI).then(() => {
1515
console.log('Mongoose connected!')
16-
})
16+
});
17+
1718
app.use(passport.initialize());
1819

1920
app.set('view engine', 'ejs');
@@ -25,10 +26,10 @@ const userRoutes = require('./routes/user.routes.js');
2526
app.use('/', urlRoutes);
2627
app.use('/user', userRoutes);
2728

28-
app.use(express.static(path.join(__dirname, "public"), {
29+
app.use(express.static(path.join(__dirname, "public"), {
2930
setHeaders: (res, path) => {
3031
res.status(200);
31-
res.setHeader('Cache-Control', 'public, max-age=31536000');
32+
res.setHeader('Cache-Control', 'public, max-age=1209600'); // 7 days caching
3233
}
3334
}));
3435

@@ -38,4 +39,4 @@ app.use((req, res) => {
3839

3940
const PORT = process.env.PORT || 9000;
4041

41-
app.listen(PORT, () => { console.log(`App running on PORT: ${PORT}`); })
42+
app.listen(PORT, () => { console.log(`App running on PORT: ${PORT}`); });

backend/connection.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const mongoose = require('mongoose');
22

3-
async function connectToMongoDB(url) {
3+
module.exports.connectToMongoDB = (url) => {
44
return mongoose.connect(url);
5-
}
6-
7-
module.exports = connectToMongoDB;
5+
}

backend/middlewares/auth.middlewares.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ module.exports.restrictToUserLogin = async (req, res, next) => {
2424
}
2525

2626
if (req.headers.accept?.includes('text/html')) {
27-
return res.redirect('/user/login');
27+
res.redirect('/user/login');
2828
} else {
29-
return res.status(401).json({ message: 'Unauthorized' });
29+
res.status(401).json({ message: 'Unauthorized' });
3030
}
3131
} catch (err) {
3232
console.error(err);
@@ -42,5 +42,5 @@ module.exports.restrictToLoginedUser = (req, res, next) => {
4242
if (!user)
4343
return next();
4444

45-
return res.redirect('/');
45+
res.redirect('/');
4646
}

0 commit comments

Comments
 (0)