-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix backend, add .vscode in order to keep settings for vscode/project…
… in repo
- Loading branch information
daniel
committed
Nov 20, 2019
1 parent
c3c2d6c
commit 6b5e81b
Showing
8 changed files
with
106 additions
and
38 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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
node_modules | ||
.env | ||
.vscode | ||
dist | ||
dist |
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,20 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Node Inspector", | ||
"type": "node", | ||
"request": "launch", | ||
"args": ["${workspaceRoot}/src/index.ts"], | ||
"runtimeArgs": ["-r", "ts-node/register"], | ||
"cwd": "${workspaceRoot}", | ||
"protocol": "inspector", | ||
"internalConsoleOptions": "openOnSessionStart", | ||
"env": { | ||
"TS_NODE_IGNORE": "false" | ||
}} | ||
] | ||
} |
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 @@ | ||
use Node Inspector to debug in vscode |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -1,55 +1,60 @@ | ||
import bodyParser from 'body-parser'; | ||
import cors from 'cors'; | ||
import express from 'express'; | ||
import { deletePuppy, getPuppies, getPuppy, reStore, adoptPuppy } from './middleware/puppies'; | ||
import * as action from './middleware/puppies'; | ||
|
||
const app = express(); | ||
console.log('enable cors'); | ||
// Aapp.use(cors()); | ||
|
||
app.use(cors({ origin: 'http://localhost:3000' })); | ||
|
||
app.use(cors()); | ||
// parse application/x-www-form-urlencoded | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
|
||
// parse application/json | ||
app.use(bodyParser.json()); | ||
|
||
// app.use((req, res) => { | ||
// console.log(req.body); | ||
// res.on("finish", () => { | ||
// console.log(res); | ||
// }); | ||
// }); | ||
|
||
app.get('/', (_req, res) => { | ||
res.send('Hello Buba3!'); | ||
}); | ||
|
||
app.get('/puppies', getPuppies, (_req, res) => { | ||
app.get('/puppies', action.getPuppies, (_req, res) => { | ||
const { puppies } = res.locals; | ||
|
||
res.json(puppies); | ||
}); | ||
|
||
app.get('/puppy/:id', getPuppy, (_req, res) => { | ||
app.get('/puppy/:id', action.getPuppy, (_req, res) => { | ||
const { puppy } = res.locals; | ||
|
||
res.json(puppy); | ||
}); | ||
|
||
app.patch('/adoptPuppy/:id', adoptPuppy, (_req, res) => { | ||
app.delete('/puppy/:id', action.deletePuppy, (_req, res) => { | ||
const { message } = res.locals; | ||
const status = message.type === 'success' ? 204 : 404; | ||
|
||
res.status(status).send(message); | ||
res.send(message.body).status(status); | ||
}); | ||
|
||
app.delete('/puppy/:id', deletePuppy, (_req, res) => { | ||
app.post('/restore', action.reStore, (_req, res) => { | ||
const { message } = res.locals; | ||
const status = message.type === 'success' ? 204 : 404; | ||
|
||
res.status(status).send(message); | ||
}); | ||
|
||
app.post('/restore', reStore, (_req, res) => { | ||
const { message } = res.locals; | ||
const status = message.type === 'success' ? 204 : 404; | ||
app.patch('/adoptPuppy/:id', action.adoptPuppy, (_req, res) => { | ||
const { puppy } = res.locals; | ||
const status = puppy ? 204 : 404; | ||
|
||
res.status(status).send(message); | ||
res.send(puppy).status(status); | ||
}); | ||
|
||
export default app; | ||
|
||
|
||
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