-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Mcdavid95/ch-setup-express-server-167024078
#167024078: Setup express server
- Loading branch information
Showing
5 changed files
with
4,658 additions
and
186 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,9 @@ | ||
{ | ||
"presets": ["@babel/preset-env"], | ||
// "plugins": [ | ||
// ["transform-runtime", { | ||
// "polyfill": false, | ||
// "regenerator": true | ||
// }] | ||
// ] | ||
} |
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,14 @@ | ||
import bunyan from 'bunyan'; | ||
|
||
export const logger = () => { | ||
const log = bunyan.createLogger({ name: 'myapp' }); | ||
return log; | ||
}; | ||
|
||
export const handleServerError = (res, error) => { | ||
logger().error(error); | ||
return res.status(500).send({ | ||
status: 'error', | ||
error: 'Internal Server Error' | ||
}); | ||
}; |
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 helmet from 'helmet'; | ||
import cors from 'cors'; | ||
import morgan from 'morgan'; | ||
import { logger } from './helpers/utils'; | ||
|
||
const app = express(); | ||
// Log requests to the console. | ||
app.use(morgan('dev')); | ||
|
||
app.use(helmet()) | ||
.disable('x-powered-by') | ||
.use(cors()); | ||
app.use(express.json()); | ||
|
||
app.get('/api/v1', (req, res) => res.status(200).send({ | ||
status: 'success', | ||
message: 'Welcome Save A Seat API' | ||
})); | ||
|
||
app.listen(1337); | ||
logger().info('app running on port ', 1337); |
Oops, something went wrong.