Skip to content

Commit 9ebb940

Browse files
committed
Setup for Vercel and Heroku
1 parent 211d199 commit 9ebb940

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+10786
-0
lines changed

.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["next/babel"]
3+
}

.eslintignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
.next
3+
dist
4+
out
5+
server/migration
6+
server/index.js
7+
server/lambda.js
8+
server/lambda_migration.js

.eslintrc.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module.exports = {
2+
root: true,
3+
extends: [
4+
'eslint:recommended',
5+
'plugin:react/recommended',
6+
'plugin:@typescript-eslint/recommended',
7+
'plugin:@typescript-eslint/eslint-recommended',
8+
'prettier'
9+
],
10+
plugins: ['@typescript-eslint', 'react'],
11+
parser: '@typescript-eslint/parser',
12+
env: {
13+
browser: true,
14+
node: true,
15+
es6: true
16+
},
17+
settings: {
18+
react: {
19+
version: 'detect'
20+
}
21+
},
22+
parserOptions: {
23+
sourceType: 'module',
24+
ecmaFeatures: {
25+
jsx: true
26+
}
27+
},
28+
rules: {
29+
'react/react-in-jsx-scope': 'off',
30+
'@typescript-eslint/explicit-module-boundary-types': 'off'
31+
},
32+
overrides: [
33+
{
34+
files: ['*.js'],
35+
rules: { '@typescript-eslint/no-var-requires': ['off'] }
36+
}
37+
]
38+
}

.gitignore

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
21+
# debug
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*
25+
26+
# local env files
27+
.env
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# server
34+
server/**/$*.ts
35+
server/**/*.db
36+
server/index.js
37+
server/upload/

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/who-is-op.iml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": false,
3+
"trailingComma": "none",
4+
"singleQuote": true
5+
}

.vscode/extensions.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["dbaeumer.vscode-eslint", "prisma.prisma"]
3+
}

.vscode/settings.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"eslint.run": "onSave",
3+
"editor.codeActionsOnSave": {
4+
"source.fixAll.eslint": true
5+
},
6+
"editor.defaultFormatter": "esbenp.prettier-vscode",
7+
"editor.formatOnSave": true,
8+
"typescript.tsdk": "node_modules/typescript/lib"
9+
}

Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM node:14.17.5
2+
3+
RUN mkdir /src
4+
RUN mkdir /src/server
5+
6+
WORKDIR /src
7+
8+
COPY /server/package.json /server/yarn.lock ./server/
9+
RUN yarn install --cwd ./server
10+
11+
COPY . .
12+
13+
EXPOSE 8080
14+
CMD yarn migrate:dev && yarn generate:server && yarn build:server && yarn start:server

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
```
12+
13+
Open [http://localhost:8000](http://localhost:8000) with your browser to see the result.
14+
15+
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
16+
17+
## Learn More
18+
19+
To learn more about Next.js, take a look at the following resources:
20+
21+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
22+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
23+
24+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
25+
26+
## Deploy on Vercel
27+
28+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/import?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
29+
30+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

aspida.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require('dotenv').config({ path: 'server/.env' })
2+
3+
module.exports = {
4+
input: 'server/api',
5+
baseURL: `${process.env.API_ORIGIN || ''}${process.env.API_BASE_PATH || ''}`
6+
}

components/UserBanner.tsx

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { useState, useCallback } from 'react'
2+
import styles from '~/styles/UserBanner.module.css'
3+
import { apiClient } from '~/utils/apiClient'
4+
import type { UserInfo } from '$/types'
5+
import type { ChangeEvent } from 'react'
6+
7+
const UserBanner = () => {
8+
const [isLoggedIn, setIsLoggedIn] = useState(false)
9+
const [token, setToken] = useState('')
10+
const [userInfo, setUserInfo] = useState({} as UserInfo)
11+
12+
const editIcon = useCallback(
13+
async (e: ChangeEvent<HTMLInputElement>) => {
14+
if (!e.target.files?.length) return
15+
16+
setUserInfo(
17+
await apiClient.user.$post({
18+
headers: { authorization: token },
19+
body: { icon: e.target.files[0] }
20+
})
21+
)
22+
},
23+
[token]
24+
)
25+
26+
const login = useCallback(async () => {
27+
const id = prompt('Enter the user id (See server/.env)')
28+
const pass = prompt('Enter the user pass (See server/.env)')
29+
if (!id || !pass) return alert('Login failed')
30+
31+
let newToken = ''
32+
33+
try {
34+
newToken = `Bearer ${
35+
(await apiClient.token.$post({ body: { id, pass } })).token
36+
}`
37+
setToken(newToken)
38+
} catch (e) {
39+
return alert('Login failed')
40+
}
41+
42+
setUserInfo(
43+
await apiClient.user.$get({ headers: { authorization: newToken } })
44+
)
45+
setIsLoggedIn(true)
46+
}, [])
47+
48+
const logout = useCallback(() => {
49+
setToken('')
50+
setIsLoggedIn(false)
51+
}, [])
52+
53+
return (
54+
<div className={styles.userBanner}>
55+
{isLoggedIn ? (
56+
<>
57+
<img src={userInfo.icon} className={styles.userIcon} />
58+
<span>{userInfo.name}</span>
59+
<input type="file" accept="image/*" onChange={editIcon} />
60+
<button onClick={logout}>LOGOUT</button>
61+
</>
62+
) : (
63+
<button onClick={login}>LOGIN</button>
64+
)}
65+
</div>
66+
)
67+
}
68+
69+
export default UserBanner

docker-compose.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: "3.8"
2+
3+
services:
4+
app:
5+
build: .
6+
ports:
7+
- "8080:8080"
8+
depends_on:
9+
- db
10+
links:
11+
- db
12+
13+
db:
14+
image: mysql:5.7
15+
ports:
16+
- "3306:3306"

heroku.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build:
2+
docker:
3+
web: Dockerfile

jest.config.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { pathsToModuleNameMapper } from 'ts-jest/utils'
2+
import type { Config } from '@jest/types'
3+
import { compilerOptions } from './tsconfig.json'
4+
5+
const config: { projects: Config.InitialOptions[] } = {
6+
projects: [
7+
{
8+
testPathIgnorePatterns: ['<rootDir>/server'],
9+
transform: {
10+
'^.+\\.tsx$': 'babel-jest',
11+
'^.+\\.ts$': 'ts-jest'
12+
},
13+
moduleNameMapper: {
14+
'\\.(css|less|sass|scss)$': 'identity-obj-proxy',
15+
'\\.(gif|ttf|eot|svg|png)$': '<rootDir>/test/__mocks__/fileMock.js',
16+
...pathsToModuleNameMapper(compilerOptions.paths, {
17+
prefix: '<rootDir>/'
18+
})
19+
}
20+
},
21+
{
22+
preset: 'ts-jest',
23+
testEnvironment: 'node',
24+
testMatch: ['<rootDir>/server/test/**/*.ts'],
25+
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
26+
prefix: '<rootDir>/'
27+
})
28+
}
29+
]
30+
}
31+
32+
export default config

next-env.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/types/global" />

0 commit comments

Comments
 (0)