mirror of https://github.com/codefeathers/magnet
Muthu Kumar
7 years ago
commit
8db12515a8
8 changed files with 224 additions and 0 deletions
@ -0,0 +1,61 @@ |
|||
# Logs |
|||
logs |
|||
*.log |
|||
npm-debug.log* |
|||
yarn-debug.log* |
|||
yarn-error.log* |
|||
|
|||
# Runtime data |
|||
pids |
|||
*.pid |
|||
*.seed |
|||
*.pid.lock |
|||
|
|||
# Directory for instrumented libs generated by jscoverage/JSCover |
|||
lib-cov |
|||
|
|||
# Coverage directory used by tools like istanbul |
|||
coverage |
|||
|
|||
# nyc test coverage |
|||
.nyc_output |
|||
|
|||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) |
|||
.grunt |
|||
|
|||
# Bower dependency directory (https://bower.io/) |
|||
bower_components |
|||
|
|||
# node-waf configuration |
|||
.lock-wscript |
|||
|
|||
# Compiled binary addons (https://nodejs.org/api/addons.html) |
|||
build/Release |
|||
|
|||
# Dependency directories |
|||
node_modules/ |
|||
jspm_packages/ |
|||
|
|||
# Typescript v1 declaration files |
|||
typings/ |
|||
|
|||
# Optional npm cache directory |
|||
.npm |
|||
|
|||
# Optional eslint cache |
|||
.eslintcache |
|||
|
|||
# Optional REPL history |
|||
.node_repl_history |
|||
|
|||
# Output of 'npm pack' |
|||
*.tgz |
|||
|
|||
# Yarn Integrity file |
|||
.yarn-integrity |
|||
|
|||
# dotenv environment variables file |
|||
.env |
|||
|
|||
# next.js build output |
|||
.next |
@ -0,0 +1,20 @@ |
|||
var express = require('express'); |
|||
var path = require('path'); |
|||
var cookieParser = require('cookie-parser'); |
|||
var logger = require('morgan'); |
|||
|
|||
var indexRouter = require('./routes/index'); |
|||
var usersRouter = require('./routes/users'); |
|||
|
|||
var app = express(); |
|||
|
|||
app.use(logger('dev')); |
|||
app.use(express.json()); |
|||
app.use(express.urlencoded({ extended: false })); |
|||
app.use(cookieParser()); |
|||
app.use(express.static(path.join(__dirname, 'public'))); |
|||
|
|||
app.use('/', indexRouter); |
|||
app.use('/users', usersRouter); |
|||
|
|||
module.exports = app; |
@ -0,0 +1,90 @@ |
|||
#!/usr/bin/env node |
|||
|
|||
/** |
|||
* Module dependencies. |
|||
*/ |
|||
|
|||
var app = require('../app'); |
|||
var debug = require('debug')('magnet:server'); |
|||
var http = require('http'); |
|||
|
|||
/** |
|||
* Get port from environment and store in Express. |
|||
*/ |
|||
|
|||
var port = normalizePort(process.env.PORT || '3000'); |
|||
app.set('port', port); |
|||
|
|||
/** |
|||
* Create HTTP server. |
|||
*/ |
|||
|
|||
var server = http.createServer(app); |
|||
|
|||
/** |
|||
* Listen on provided port, on all network interfaces. |
|||
*/ |
|||
|
|||
server.listen(port); |
|||
server.on('error', onError); |
|||
server.on('listening', onListening); |
|||
|
|||
/** |
|||
* Normalize a port into a number, string, or false. |
|||
*/ |
|||
|
|||
function normalizePort(val) { |
|||
var port = parseInt(val, 10); |
|||
|
|||
if (isNaN(port)) { |
|||
// named pipe |
|||
return val; |
|||
} |
|||
|
|||
if (port >= 0) { |
|||
// port number |
|||
return port; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* Event listener for HTTP server "error" event. |
|||
*/ |
|||
|
|||
function onError(error) { |
|||
if (error.syscall !== 'listen') { |
|||
throw error; |
|||
} |
|||
|
|||
var bind = typeof port === 'string' |
|||
? 'Pipe ' + port |
|||
: 'Port ' + port; |
|||
|
|||
// handle specific listen errors with friendly messages |
|||
switch (error.code) { |
|||
case 'EACCES': |
|||
console.error(bind + ' requires elevated privileges'); |
|||
process.exit(1); |
|||
break; |
|||
case 'EADDRINUSE': |
|||
console.error(bind + ' is already in use'); |
|||
process.exit(1); |
|||
break; |
|||
default: |
|||
throw error; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Event listener for HTTP server "listening" event. |
|||
*/ |
|||
|
|||
function onListening() { |
|||
var addr = server.address(); |
|||
var bind = typeof addr === 'string' |
|||
? 'pipe ' + addr |
|||
: 'port ' + addr.port; |
|||
debug('Listening on ' + bind); |
|||
} |
@ -0,0 +1,14 @@ |
|||
{ |
|||
"name": "magnet", |
|||
"version": "0.0.0", |
|||
"private": true, |
|||
"scripts": { |
|||
"start": "node ./bin/www" |
|||
}, |
|||
"dependencies": { |
|||
"cookie-parser": "~1.4.3", |
|||
"debug": "~2.6.9", |
|||
"express": "~4.16.0", |
|||
"morgan": "~1.9.0" |
|||
} |
|||
} |
@ -0,0 +1,13 @@ |
|||
<html> |
|||
|
|||
<head> |
|||
<title>Express</title> |
|||
<link rel="stylesheet" href="/stylesheets/style.css"> |
|||
</head> |
|||
|
|||
<body> |
|||
<h1>Express</h1> |
|||
<p>Welcome to Express</p> |
|||
</body> |
|||
|
|||
</html> |
@ -0,0 +1,8 @@ |
|||
body { |
|||
padding: 50px; |
|||
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; |
|||
} |
|||
|
|||
a { |
|||
color: #00B7FF; |
|||
} |
@ -0,0 +1,9 @@ |
|||
var express = require('express'); |
|||
var router = express.Router(); |
|||
|
|||
/* GET home page. */ |
|||
router.get('/', function(req, res, next) { |
|||
res.render('index', { title: 'Express' }); |
|||
}); |
|||
|
|||
module.exports = router; |
@ -0,0 +1,9 @@ |
|||
var express = require('express'); |
|||
var router = express.Router(); |
|||
|
|||
/* GET users listing. */ |
|||
router.get('/', function(req, res, next) { |
|||
res.send('respond with a resource'); |
|||
}); |
|||
|
|||
module.exports = router; |
Loading…
Reference in new issue