Skip to content

Commit

Permalink
Merge pull request #2 from JonathanBout/main
Browse files Browse the repository at this point in the history
Docker fixes
  • Loading branch information
JonathanBout authored Mar 9, 2024
2 parents d4faf91 + 386c13e commit f6ea3a6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 35 deletions.
35 changes: 18 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
FROM node:lts-alpine

# install simple http server for serving static content
RUN npm install -g http-server

# make the 'app' folder the current working directory
# Use the node image from official Docker Hub
FROM node:lts-alpine as build-stage
# set the working directory
WORKDIR /app

# copy both 'package.json' and 'package-lock.json' (if available)
# Copy the working directory in the container
COPY package*.json ./

# install project dependencies
# Install the project dependencies
RUN npm install

# copy project files and folders to the current working directory (i.e. 'app' folder)
# Copy the rest of the project files to the container
COPY . .

# build app for production with minification
# Build the Vue.js application to the production mode to dist folder
RUN npm run build

EXPOSE 5000
CMD [ "http-server", "dist", "-p", "5000" ]
# Use the lightweight Nginx image from the previous stage for the nginx container
FROM nginx:stable-alpine as production-stage
WORKDIR /app
# Copy the build application from the previous stage to the Nginx container
COPY --from=build-stage /app/dist ./
# Copy the nginx configuration file
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
# Expose the port 80
EXPOSE 80
# Start Nginx to serve the application
CMD ["nginx", "-g", "daemon off;"]
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ services:
environment:
NODE_ENV: production
ports:
- 20000:5000
- 20000:80
9 changes: 9 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
server {
listen 80;
server_name localhost;
root /app;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
12 changes: 6 additions & 6 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '@/views/IndexView.vue'
import IndexView from '@/views/IndexView.vue'

const formatDate = (date: Date) => {
return `/${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`
}

const randomDate = () => {
const randomDateUrl = () => {
const start = new Date(1995, 5, 16)
const end = new Date()
const date = new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()))
return formatDate(date)
}

const today = () => formatDate(new Date())
const todayUrl = () => formatDate(new Date())

const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'home',
redirect: today
redirect: todayUrl
},
{
path: '/:year([0-9]{4})/:month([0-9]{1,2})/:day([0-9]{1,2})',
name: 'apod',
component: HomeView
component: IndexView
},
{
path: '/random',
name: 'picker',
redirect: randomDate
redirect: randomDateUrl
},
{
path: '/:catchAll(.*)',
Expand Down
15 changes: 4 additions & 11 deletions src/views/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ const pathFromDate = (date: Date) => {
const load = async () => {
loading.value = true
if (
route.params.year != date.value.getFullYear().toString() ||
route.params.month != (date.value.getMonth() + 1).toString() ||
route.params.day != date.value.getDate().toString()
) {
router.push(pathFromDate(date.value) ?? '/')
}
response.value = await api.getApod(date.value)
loading.value = false
}
Expand All @@ -57,10 +50,10 @@ watch(date, load)
<div class="apod">
<div class="nav separated">
<span>
<router-link :to="{ path: pathFromDate(addDays(date, -1)) }">Previous Day</router-link>
<a :href="pathFromDate(addDays(date, -1))">Previous Day</a>
</span>
<span>
<router-link to="/random">Random</router-link>
<a href="/random">Random</a>
</span>
<span>
<input
Expand All @@ -72,10 +65,10 @@ watch(date, load)
/>
</span>
<span>
<router-link to="/">Today</router-link>
<a href="/">Today</a>
</span>
<span>
<router-link :to="{ path: pathFromDate(addDays(date, 1)) }">Next Day</router-link>
<a :href="pathFromDate(addDays(date, 1))">Next Day</a>
</span>
</div>
<template v-if="has_error()">
Expand Down

0 comments on commit f6ea3a6

Please sign in to comment.