-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
163 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PORT=8000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PORT= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"env": { | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"extends": ["standard-with-typescript", "prettier"], | ||
"plugins": ["prettier"], | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"prettier/prettier": [ | ||
"error", | ||
{ | ||
"semi": true, | ||
"tabWidth": 2, | ||
"printWidth": 140, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"bracketSameLine": false, | ||
"arrowParens": "always" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"semi": true, | ||
"printWidth": 140, | ||
"tabWidth": 2, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"arrowParens": "always", | ||
"bracketSpacing": true | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
declare global { | ||
namespace NodeJS { | ||
interface ProcessEnv { | ||
[key: string]: string | undefined; | ||
PORT: string; | ||
} | ||
} | ||
} | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { type Request, type Response } from 'express'; | ||
import usersModel from '../models/user'; | ||
|
||
function getAllUsers(req: Request, res: Response): void { | ||
const users = usersModel.getUsers(); | ||
res.status(200).json(users); | ||
} | ||
|
||
export default { | ||
getAllUsers, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import express from 'express'; | ||
import dotenv from 'dotenv'; | ||
import cors from 'cors'; | ||
|
||
import routes from './routes/index'; | ||
|
||
dotenv.config(); | ||
|
||
const app = express(); | ||
const PORT = process.env.PORT ?? 3000; | ||
|
||
app.use(cors()); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json()); | ||
|
||
app.use(`/api`, routes); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Server is running on port ${PORT}`); | ||
}); | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
interface User { | ||
name: string; | ||
descrition: string; | ||
} | ||
|
||
class UsersModel { | ||
users: User[]; | ||
|
||
constructor() { | ||
this.users = [ | ||
{ name: 'RulerChen', descrition: 'Author of this project' }, | ||
{ name: 'joshtu0627', descrition: 'Author of this project' }, | ||
]; | ||
} | ||
|
||
getUsers(): User[] { | ||
return this.users; | ||
} | ||
} | ||
|
||
const usersModel = new UsersModel(); | ||
|
||
export default usersModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import express from 'express'; | ||
|
||
import UserRoutes from './user'; | ||
|
||
const router = express.Router(); | ||
|
||
router.get('/', (req, res) => { | ||
res.send('This is the API root!'); | ||
}); | ||
|
||
router.use('/users', UserRoutes); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import express from 'express'; | ||
|
||
import UserController from '../controllers/user'; | ||
|
||
const router = express.Router(); | ||
|
||
router.get('/', UserController.getAllUsers); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"baseUrl": "src", | ||
"outDir": "build", | ||
"sourceMap": true, | ||
"strict": true, | ||
"types": ["node"] | ||
}, | ||
"include": ["process.env.d.ts", "./src/**/*.ts"] | ||
} |