mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 15:05:35 +00:00
Update deps & add docker
This commit is contained in:
4
.prettierrc
Normal file
4
.prettierrc
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false
|
||||||
|
}
|
||||||
32
config.ts
32
config.ts
@@ -1,33 +1,3 @@
|
|||||||
// const NEXT_PUBLIC_PREFIX = 'NEXT_PUBLIC_';
|
|
||||||
|
|
||||||
// const getEnvironmentVariable = (environmentVariable: string = ''): string => {
|
|
||||||
// if (!environmentVariable.startsWith(NEXT_PUBLIC_PREFIX)) {
|
|
||||||
// throw new Error(
|
|
||||||
// `Env var must start with "${NEXT_PUBLIC_PREFIX}": ${environmentVariable}`
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const envVarObject = Object
|
|
||||||
// .entries(process.env)
|
|
||||||
// .map(([key, value]) => ({ name: key, value }))
|
|
||||||
// .find((env) => {
|
|
||||||
// console.log(env.name === environmentVariable);
|
|
||||||
// return env.name === environmentVariable;
|
|
||||||
// });
|
|
||||||
|
|
||||||
// console.log('envVarObject', envVarObject, process.env.NEXT_PUBLIC_SITE_NAME)
|
|
||||||
|
|
||||||
// if (!envVarObject) {
|
|
||||||
// throw new Error(
|
|
||||||
// `Couldn't find environment variable: ${environmentVariable}`
|
|
||||||
// );
|
|
||||||
// } else {
|
|
||||||
// return envVarObject.value;
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
siteName: process.env.NEXT_PUBLIC_SITE_NAME // getEnvironmentVariable(NEXT_PUBLIC_PREFIX + 'SITE_NAME'),
|
siteName: "My Links",
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('config', config)
|
|
||||||
5
docker/.dockerignore
Normal file
5
docker/.dockerignore
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
node_modules
|
||||||
|
.env
|
||||||
|
.next
|
||||||
|
.vscode
|
||||||
|
example.env
|
||||||
12
docker/Dockerfile
Normal file
12
docker/Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
FROM node:18-alpine3.17
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY ./ /app
|
||||||
|
|
||||||
|
RUN npm install
|
||||||
|
RUN npx prisma generate
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD npx prisma migrate deploy && npm run start
|
||||||
1
docker/build.sh
Executable file
1
docker/build.sh
Executable file
@@ -0,0 +1 @@
|
|||||||
|
docker build -f ./Dockerfile -t sonny/my-links ../
|
||||||
37
docker/docker-compose.yml
Normal file
37
docker/docker-compose.yml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
version: "3.8"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_volume_data:
|
||||||
|
driver: local
|
||||||
|
|
||||||
|
networks:
|
||||||
|
my_links_net:
|
||||||
|
name: my_links_net
|
||||||
|
|
||||||
|
services:
|
||||||
|
my-links-db:
|
||||||
|
image: mysql:latest
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- db_volume_data:/var/lib/postgresql/data
|
||||||
|
environment:
|
||||||
|
MYSQL_USER: ${DB_USER}
|
||||||
|
MYSQL_PASSWORD: ${DB_PASSWORD}
|
||||||
|
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
|
||||||
|
MYSQL_DATABASE: ${DB_DATABASE}
|
||||||
|
networks:
|
||||||
|
- my_links_net
|
||||||
|
|
||||||
|
my-links:
|
||||||
|
image: sonny/my-links:latest
|
||||||
|
container_name: MyLinks
|
||||||
|
ports:
|
||||||
|
- 3000:3000
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
DATABASE_URL: "mysql://${DB_USER}:${DB_PASSWORD}@my-links-db:3306/${DB_DATABASE}"
|
||||||
|
depends_on:
|
||||||
|
my-links-db:
|
||||||
|
condition: service_started
|
||||||
|
networks:
|
||||||
|
- my_links_net
|
||||||
1
docker/start.sh
Executable file
1
docker/start.sh
Executable file
@@ -0,0 +1 @@
|
|||||||
|
docker-compose --env-file ../.env -f ./docker-compose.yml up -d
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
DATABASE_URL="mysql://root:root@127.0.0.1:3306/MyLinks"
|
DB_USER="my_user"
|
||||||
|
DB_PASSWORD=""
|
||||||
|
DB_DATABASE="my-links"
|
||||||
|
|
||||||
NEXTAUTH_URL=http://localhost:3000
|
NEXTAUTH_URL=http://localhost:3000
|
||||||
NEXTAUTH_URL_INTERNAL=http://localhost:3000
|
NEXTAUTH_URL_INTERNAL=http://localhost:3000
|
||||||
|
|||||||
4336
package-lock.json
generated
4336
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@@ -8,30 +8,27 @@
|
|||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dnd-kit/core": "^5.0.3",
|
"@prisma/client": "^4.10.0",
|
||||||
"@dnd-kit/sortable": "^6.0.1",
|
"@svgr/webpack": "^6.5.1",
|
||||||
"@dnd-kit/utilities": "^3.1.0",
|
"axios": "^1.3.2",
|
||||||
"@prisma/client": "^4.3.1",
|
"next": "^13.1.6",
|
||||||
"@svgr/webpack": "^6.2.1",
|
"next-auth": "^4.19.2",
|
||||||
"axios": "^0.27.2",
|
"next-connect": "^0.13.0",
|
||||||
"next": "^12.3.0",
|
|
||||||
"next-auth": "^4.0.6",
|
|
||||||
"next-connect": "^0.12.2",
|
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-confirm-alert": "^2.8.0",
|
"react-confirm-alert": "^3.0.6",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-select": "^5.3.1",
|
"react-select": "^5.7.0",
|
||||||
"sass": "^1.46.0",
|
"sass": "^1.58.0",
|
||||||
"sharp": "^0.30.4",
|
"sharp": "^0.31.3",
|
||||||
"toastr": "^2.1.4"
|
"toastr": "^2.1.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^17.0.29",
|
"@types/node": "^18.13.0",
|
||||||
"@types/nprogress": "^0.2.0",
|
"@types/nprogress": "^0.2.0",
|
||||||
"@types/react": "^18.0.8",
|
"@types/react": "^18.0.27",
|
||||||
"eslint": "7",
|
"eslint": "8",
|
||||||
"eslint-config-next": "12.0.7",
|
"eslint-config-next": "13.1.6",
|
||||||
"prisma": "^4.3.1"
|
"prisma": "^4.10.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
108
pages/index.tsx
108
pages/index.tsx
@@ -1,69 +1,79 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from "react";
|
||||||
import { useSession } from 'next-auth/react';
|
import { useSession } from "next-auth/react";
|
||||||
import Head from 'next/head';
|
import Head from "next/head";
|
||||||
|
|
||||||
import Menu from '../components/Categories/SideMenu';
|
import Menu from "../components/Categories/SideMenu";
|
||||||
import Links from '../components/Links/Links';
|
import Links from "../components/Links/Links";
|
||||||
|
|
||||||
import { Category, Link } from '../types';
|
import { Category, Link } from "../types";
|
||||||
|
|
||||||
import { BuildCategory } from '../utils/front';
|
import { BuildCategory } from "../utils/front";
|
||||||
import { prisma } from '../utils/back';
|
import { prisma } from "../utils/back";
|
||||||
|
|
||||||
import { config } from '../config';
|
import { config } from "../config";
|
||||||
|
|
||||||
interface HomeProps {
|
interface HomeProps {
|
||||||
categories: Category[];
|
categories: Category[];
|
||||||
favorites: Link[];
|
favorites: Link[];
|
||||||
}
|
}
|
||||||
|
|
||||||
function Home({ categories, favorites }: HomeProps) {
|
function Home({ categories, favorites }: HomeProps) {
|
||||||
const { data } = useSession({ required: true });
|
const { data } = useSession({ required: true });
|
||||||
const [categoryActive, setCategoryActive] = useState<Category | null>(categories?.[0]);
|
const [categoryActive, setCategoryActive] = useState<Category | null>(
|
||||||
|
categories?.[0]
|
||||||
|
);
|
||||||
|
|
||||||
const handleSelectCategory = (category: Category) => setCategoryActive(category);
|
const handleSelectCategory = (category: Category) =>
|
||||||
|
setCategoryActive(category);
|
||||||
|
|
||||||
return (<>
|
return (
|
||||||
<Head>
|
<>
|
||||||
<title>{config.siteName}</title>
|
<Head>
|
||||||
</Head>
|
<title>{config.siteName}</title>
|
||||||
<div className='App'>
|
</Head>
|
||||||
<Menu
|
<div className="App">
|
||||||
categories={categories}
|
<Menu
|
||||||
favorites={favorites}
|
categories={categories}
|
||||||
handleSelectCategory={handleSelectCategory}
|
favorites={favorites}
|
||||||
categoryActive={categoryActive}
|
handleSelectCategory={handleSelectCategory}
|
||||||
session={data}
|
categoryActive={categoryActive}
|
||||||
/>
|
session={data}
|
||||||
<Links category={categoryActive} />
|
/>
|
||||||
</div>
|
<Links category={categoryActive} />
|
||||||
</>);
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getServerSideProps() {
|
export async function getServerSideProps() {
|
||||||
const categoriesDB = await prisma.category.findMany({ include: { links: true } });
|
const categoriesDB = await prisma.category.findMany({
|
||||||
|
include: { links: true },
|
||||||
|
});
|
||||||
|
|
||||||
const favorites = [] as Link[];
|
const favorites = [] as Link[];
|
||||||
const categories = categoriesDB.map((categoryDB) => {
|
const categories = categoriesDB.map((categoryDB) => {
|
||||||
const category = BuildCategory(categoryDB);
|
const category = BuildCategory(categoryDB);
|
||||||
category.links.map((link) => link.favorite ? favorites.push(link) : null);
|
category.links.map((link) =>
|
||||||
return category;
|
link.favorite ? favorites.push(link) : null
|
||||||
});
|
);
|
||||||
|
return category;
|
||||||
|
});
|
||||||
|
|
||||||
if (categories.length === 0) {
|
if (categories.length === 0) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
destination: '/category/create?info=Veuillez créer une catégorie'
|
destination:
|
||||||
}
|
"/category/create?info=Veuillez créer une catégorie",
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
categories: JSON.parse(JSON.stringify(categories)),
|
categories: JSON.parse(JSON.stringify(categories)),
|
||||||
favorites: JSON.parse(JSON.stringify(favorites)),
|
favorites: JSON.parse(JSON.stringify(favorites)),
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Home.authRequired = true;
|
Home.authRequired = true;
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
# Please do not edit this file manually
|
|
||||||
# It should be added in your version-control system (i.e. Git)
|
|
||||||
provider = "mysql"
|
|
||||||
Reference in New Issue
Block a user