File tree Expand file tree Collapse file tree 5 files changed +8
-57
lines changed Expand file tree Collapse file tree 5 files changed +8
-57
lines changed Original file line number Diff line number Diff line change @@ -2,17 +2,17 @@ const express = require('express')
22const logger = require ( 'morgan' )
33const cors = require ( 'cors' )
44
5- const indexRouter = require ( './routes/index ' )
5+ const contactsRouter = require ( './routes/api/contacts ' )
66
77const app = express ( )
88
9- const formatsLogger = app . get ( 'env' ) === 'development' ? 'dev' : 'combined '
9+ const formatsLogger = app . get ( 'env' ) === 'development' ? 'dev' : 'short '
1010
1111app . use ( logger ( formatsLogger ) )
1212app . use ( cors ( ) )
1313app . use ( express . json ( ) )
1414
15- app . use ( '/api/contacts' , indexRouter )
15+ app . use ( '/api/contacts' , contactsRouter )
1616
1717app . use ( ( req , res ) => {
1818 res . status ( 404 ) . json ( { message : 'Not found' } )
Original file line number Diff line number Diff line change 1- #!/usr/bin/env node
2-
31const app = require ( '../app' )
4- const debug = require ( 'debug' ) ( 'template:server' )
5- const http = require ( 'http' )
6-
7- const normalizePort = ( val ) => {
8- const port = parseInt ( val , 10 )
9-
10- if ( isNaN ( port ) ) {
11- return val
12- }
13-
14- if ( port >= 0 ) {
15- return port
16- }
17-
18- return false
19- }
20-
21- const port = normalizePort ( process . env . PORT || '3000' )
22- app . set ( 'port' , port )
23-
24- const server = http . createServer ( app )
25-
26- server . listen ( port )
27- server . on ( 'error' , onError )
28- server . on ( 'listening' , onListening )
29-
30- function onError ( error ) {
31- if ( error . syscall !== 'listen' ) {
32- throw error
33- }
34-
35- const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port
362
37- switch ( error . code ) {
38- case 'EACCES' :
39- console . error ( bind + ' requires elevated privileges' )
40- process . exit ( 1 )
41- case 'EADDRINUSE' :
42- console . error ( bind + ' is already in use' )
43- process . exit ( 1 )
44- default :
45- throw error
46- }
47- }
3+ const PORT = process . env . PORT || 3000
484
49- function onListening ( ) {
50- const addr = server . address ( )
51- const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr . port
52- debug ( 'Listening on ' + bind )
53- }
5+ app . listen ( PORT , ( ) => {
6+ console . log ( `Server running. Use our API on port: ${ PORT } ` )
7+ } )
Original file line number Diff line number Diff line change 44 "private" : true ,
55 "scripts" : {
66 "start" : " cross-env NODE_ENV=production node ./bin/server.js" ,
7- "start:dev" : " nodemon ./bin/server.js" ,
8- "start:debug" : " cross-env DEBUG=* nodemon ./bin/server.js" ,
7+ "start:dev" : " cross-env NODE_ENV=development nodemon ./bin/server.js" ,
98 "lint" : " eslint **/*.js" ,
109 "lint:fix" : " eslint --fix **/*.js"
1110 },
1211 "dependencies" : {
1312 "cors" : " 2.8.5" ,
1413 "cross-env" : " 7.0.3" ,
15- "debug" : " 4.3.1" ,
1614 "express" : " 4.17.1" ,
1715 "morgan" : " 1.10.0"
1816 },
Original file line number Diff line number Diff line change 2727
2828- ` npm start ` &mdash ; старт сервера в режиме production
2929- ` npm run start:dev ` &mdash ; старт сервера в режиме разработки (development)
30- - ` npm run start:debug ` &mdash ; старт сервера в режиме DEBUG
3130- ` npm run lint ` &mdash ; запустить выполнение проверки кода с eslint, необходимо выполнять перед каждым PR и исправлять все ошибки линтера
3231- ` npm lint:fix ` &mdash ; та же проверка линтера, но с автоматическими исправлениями простых ошибок
File renamed without changes.
You can’t perform that action at this time.
0 commit comments