Add 9 files
Browse files- Dockerfile +57 -0
- public/index.html +10 -0
- src/components/About.tsx +12 -0
- src/components/Todo.tsx +24 -0
- src/components/TodoList.tsx +35 -0
- src/pages///_app.tsx +18 -0
- src/pages/index.tsx +13 -0
- src/styles/globals.css +16 -0
- tsconfig.json +28 -0
Dockerfile
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
FROM node:18-alpine AS base
|
3 |
+
|
4 |
+
# Install dependencies only when needed
|
5 |
+
FROM base AS deps
|
6 |
+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
7 |
+
RUN apk add --no-cache libc6-compat
|
8 |
+
WORKDIR /app
|
9 |
+
|
10 |
+
# Install dependencies based on the preferred package manager
|
11 |
+
COPY package.json package-lock.json* ./
|
12 |
+
RUN npm install
|
13 |
+
|
14 |
+
# Uncomment the following lines if you want to use a secret at buildtime,
|
15 |
+
# for example to access your private npm packages
|
16 |
+
# RUN --mount=type=secret,id=HF_EXAMPLE_SECRET,mode=0444,required=true # $(cat /run/secrets/HF_EXAMPLE_SECRET)
|
17 |
+
|
18 |
+
# Rebuild the source code only when needed
|
19 |
+
FROM base AS builder
|
20 |
+
WORKDIR /app
|
21 |
+
COPY --from=deps /app/node_modules ./node_modules
|
22 |
+
COPY . .
|
23 |
+
|
24 |
+
# Next.js collects completely anonymous telemetry data about general usage.
|
25 |
+
# Learn more here: https://nextjs.org/telemetry
|
26 |
+
# Uncomment the following line in case you want to disable telemetry during the build.
|
27 |
+
# ENV NEXT_TELEMETRY_DISABLED 1
|
28 |
+
|
29 |
+
RUN npm run build
|
30 |
+
|
31 |
+
# Production image, copy all the files and run next
|
32 |
+
FROM base AS runner
|
33 |
+
WORKDIR /app
|
34 |
+
|
35 |
+
ENV NODE_ENV production
|
36 |
+
# Uncomment the following line in case you want to disable telemetry during runtime.
|
37 |
+
# ENV NEXT_TELEMETRY_DISABLED 1
|
38 |
+
|
39 |
+
RUN addgroup --system --gid 1001 nodejs
|
40 |
+
RUN adduser --system --uid 1001 nextjs
|
41 |
+
|
42 |
+
COPY --from=builder /app/public ./public
|
43 |
+
|
44 |
+
# Automatically leverage output traces to reduce image size
|
45 |
+
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
46 |
+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
47 |
+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
48 |
+
COPY --from=builder --chown=nextjs:nodejs /app/.next/cache ./.next/cache
|
49 |
+
# COPY --from=builder --chown=nextjs:nodejs /app/.next/cache/fetch-cache ./.next/cache/fetch-cache
|
50 |
+
|
51 |
+
USER nextjs
|
52 |
+
|
53 |
+
EXPOSE 3000
|
54 |
+
|
55 |
+
ENV PORT 3000
|
56 |
+
|
57 |
+
CMD ["node", "server.js"]
|
public/index.html
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>Todo List App</title>
|
5 |
+
</head>
|
6 |
+
<body>
|
7 |
+
<div id="root"></div>
|
8 |
+
<script src="/build/bundle.js"></script>
|
9 |
+
</body>
|
10 |
+
</html>
|
src/components/About.tsx
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React from "react";
|
2 |
+
|
3 |
+
const About = () => {
|
4 |
+
return (
|
5 |
+
<div>
|
6 |
+
<h1>About</h1>
|
7 |
+
<p>This is a simple todo list app</p>
|
8 |
+
</div>
|
9 |
+
);
|
10 |
+
};
|
11 |
+
|
12 |
+
export default About;
|
src/components/Todo.tsx
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React, { useState } from "react";
|
2 |
+
|
3 |
+
type Todo = {
|
4 |
+
id: number;
|
5 |
+
text: string;
|
6 |
+
completed: boolean;
|
7 |
+
};
|
8 |
+
|
9 |
+
const Todo: React.FC<Todo> = ({ id, text, completed }) => {
|
10 |
+
const [checked, setChecked] = useState(completed);
|
11 |
+
|
12 |
+
const handleChange = () => {
|
13 |
+
setChecked(!checked);
|
14 |
+
};
|
15 |
+
|
16 |
+
return (
|
17 |
+
<div>
|
18 |
+
<input type="checkbox" checked={checked} onChange={handleChange} />
|
19 |
+
<p>{text}</p>
|
20 |
+
</div>
|
21 |
+
);
|
22 |
+
};
|
23 |
+
|
24 |
+
export default Todo;
|
src/components/TodoList.tsx
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React, { useState } from "react";
|
2 |
+
import Todo from "./Todo";
|
3 |
+
|
4 |
+
type TodoListProps = {
|
5 |
+
todos: Todo[];
|
6 |
+
};
|
7 |
+
|
8 |
+
const TodoList: React.FC<TodoListProps> = ({ todos }) => {
|
9 |
+
const [todos, setTodos] = useState([]);
|
10 |
+
|
11 |
+
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
12 |
+
event.preventDefault();
|
13 |
+
const formData = new FormData(event.target as HTMLFormElement);
|
14 |
+
const text = formData.get("text") as string;
|
15 |
+
setTodos([...todos, { id: todos.length + 1, text, completed: false }]);
|
16 |
+
};
|
17 |
+
|
18 |
+
return (
|
19 |
+
<div>
|
20 |
+
<form onSubmit={handleSubmit}>
|
21 |
+
<input type="text" name="text" placeholder="Add a todo" />
|
22 |
+
<button type="submit">Add</button>
|
23 |
+
</form>
|
24 |
+
<ul>
|
25 |
+
{todos.map((todo) => (
|
26 |
+
<li key={todo.id}>
|
27 |
+
<Todo {...todo} />
|
28 |
+
</li>
|
29 |
+
))}
|
30 |
+
</ul>
|
31 |
+
</div>
|
32 |
+
);
|
33 |
+
};
|
34 |
+
|
35 |
+
export default TodoList;
|
src/pages///_app.tsx
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { AppProps } from "next/app";
|
2 |
+
import "../styles/globals.css";
|
3 |
+
|
4 |
+
const App = ({ Component, pageProps }: AppProps) => {
|
5 |
+
return (
|
6 |
+
<div>
|
7 |
+
<nav>
|
8 |
+
<a href="/">Home</a>
|
9 |
+
<a href="/about">About</a>
|
10 |
+
</nav>
|
11 |
+
<div>
|
12 |
+
<Component {...pageProps} />
|
13 |
+
</div>
|
14 |
+
</div>
|
15 |
+
);
|
16 |
+
};
|
17 |
+
|
18 |
+
export default App;
|
src/pages/index.tsx
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { NextPage } from "next";
|
2 |
+
import type { Todo } from "../components/Todo";
|
3 |
+
|
4 |
+
const Home: NextPage = () => {
|
5 |
+
return (
|
6 |
+
<div>
|
7 |
+
<h1>Todo List</h1>
|
8 |
+
<TodoList />
|
9 |
+
</div>
|
10 |
+
);
|
11 |
+
};
|
12 |
+
|
13 |
+
export default Home;
|
src/styles/globals.css
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
body {
|
2 |
+
font-family: Arial, sans-serif;
|
3 |
+
text-align: center;
|
4 |
+
background-color: #f0f0f0;
|
5 |
+
}
|
6 |
+
|
7 |
+
h1,
|
8 |
+
h2,
|
9 |
+
h3 {
|
10 |
+
font-weight: bold;
|
11 |
+
}
|
12 |
+
|
13 |
+
a,
|
14 |
+
a:visited {
|
15 |
+
color: #0070cc;
|
16 |
+
}
|
tsconfig.json
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"compilerOptions": {
|
3 |
+
"target": "ES2022",
|
4 |
+
"lib": ["dom", "dom.iterable", "esnext"],
|
5 |
+
"allowJs": true,
|
6 |
+
"skipLibCheck": true,
|
7 |
+
"strict": true,
|
8 |
+
"forceConsistentCasingInFileNames": true,
|
9 |
+
"noEmit": true,
|
10 |
+
"esModuleInterop": true,
|
11 |
+
"module": "esnext",
|
12 |
+
"moduleResolution": "node",
|
13 |
+
"resolveJsonModule": true,
|
14 |
+
"isolatedModules": true,
|
15 |
+
"jsx": "preserve",
|
16 |
+
"incremental": true,
|
17 |
+
"plugins": [
|
18 |
+
{
|
19 |
+
"name": "next"
|
20 |
+
}
|
21 |
+
],
|
22 |
+
"paths": {
|
23 |
+
"@/*": ["./src/*"]
|
24 |
+
}
|
25 |
+
},
|
26 |
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
27 |
+
"exclude": ["node_modules"]
|
28 |
+
}
|