Showing
12 changed files
with
194 additions
and
31 deletions
| 1 | +var createError = require('http-errors'); | ||
| 1 | var express = require('express'); | 2 | var express = require('express'); |
| 3 | +var path = require('path'); | ||
| 4 | +var cookieParser = require('cookie-parser'); | ||
| 5 | +var logger = require('morgan'); | ||
| 6 | + | ||
| 7 | +var indexRouter = require('./routes/index'); | ||
| 8 | +var usersRouter = require('./routes/users'); | ||
| 9 | + | ||
| 2 | var app = express(); | 10 | var app = express(); |
| 3 | -app.get('/', function (req, res) { | 11 | + |
| 4 | - res.send('Hello World'); | 12 | +// view engine setup |
| 5 | -}) | 13 | +app.set('views', path.join(__dirname, 'views')); |
| 6 | - | 14 | +app.set('view engine', 'ejs'); |
| 7 | -var server = app.listen(23023, function () { | 15 | + |
| 8 | - var host = server.address().address | 16 | +app.use(logger('dev')); |
| 9 | - var port = server.address().port | 17 | +app.use(express.json()); |
| 10 | - console.log("Example app listening at http://%s:%s", host, port) | 18 | +app.use(express.urlencoded({ extended: false })); |
| 11 | -}) | 19 | +app.use(cookieParser()); |
| 20 | +app.use(express.static(path.join(__dirname, 'public'))); | ||
| 21 | + | ||
| 22 | +app.use('/', indexRouter); | ||
| 23 | +app.use('/users', usersRouter); | ||
| 24 | + | ||
| 25 | +// catch 404 and forward to error handler | ||
| 26 | +app.use(function(req, res, next) { | ||
| 27 | + next(createError(404)); | ||
| 28 | +}); | ||
| 29 | + | ||
| 30 | +// error handler | ||
| 31 | +app.use(function(err, req, res, next) { | ||
| 32 | + // set locals, only providing error in development | ||
| 33 | + res.locals.message = err.message; | ||
| 34 | + res.locals.error = req.app.get('env') === 'development' ? err : {}; | ||
| 35 | + | ||
| 36 | + // render the error page | ||
| 37 | + res.status(err.status || 500); | ||
| 38 | + res.render('error'); | ||
| 39 | +}); | ||
| 40 | + | ||
| 41 | +module.exports = app; | ... | ... |
bin/www
0 → 100755
| 1 | +#!/usr/bin/env node | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Module dependencies. | ||
| 5 | + */ | ||
| 6 | + | ||
| 7 | +var app = require('../app'); | ||
| 8 | +var debug = require('debug')('kindofyourdog:server'); | ||
| 9 | +var http = require('http'); | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * Get port from environment and store in Express. | ||
| 13 | + */ | ||
| 14 | + | ||
| 15 | +var port = normalizePort(process.env.PORT || '3000'); | ||
| 16 | +app.set('port', port); | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * Create HTTP server. | ||
| 20 | + */ | ||
| 21 | + | ||
| 22 | +var server = http.createServer(app); | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | + * Listen on provided port, on all network interfaces. | ||
| 26 | + */ | ||
| 27 | + | ||
| 28 | +server.listen(port); | ||
| 29 | +server.on('error', onError); | ||
| 30 | +server.on('listening', onListening); | ||
| 31 | + | ||
| 32 | +/** | ||
| 33 | + * Normalize a port into a number, string, or false. | ||
| 34 | + */ | ||
| 35 | + | ||
| 36 | +function normalizePort(val) { | ||
| 37 | + var port = parseInt(val, 10); | ||
| 38 | + | ||
| 39 | + if (isNaN(port)) { | ||
| 40 | + // named pipe | ||
| 41 | + return val; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + if (port >= 0) { | ||
| 45 | + // port number | ||
| 46 | + return port; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + return false; | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +/** | ||
| 53 | + * Event listener for HTTP server "error" event. | ||
| 54 | + */ | ||
| 55 | + | ||
| 56 | +function onError(error) { | ||
| 57 | + if (error.syscall !== 'listen') { | ||
| 58 | + throw error; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + var bind = typeof port === 'string' | ||
| 62 | + ? 'Pipe ' + port | ||
| 63 | + : 'Port ' + port; | ||
| 64 | + | ||
| 65 | + // handle specific listen errors with friendly messages | ||
| 66 | + switch (error.code) { | ||
| 67 | + case 'EACCES': | ||
| 68 | + console.error(bind + ' requires elevated privileges'); | ||
| 69 | + process.exit(1); | ||
| 70 | + break; | ||
| 71 | + case 'EADDRINUSE': | ||
| 72 | + console.error(bind + ' is already in use'); | ||
| 73 | + process.exit(1); | ||
| 74 | + break; | ||
| 75 | + default: | ||
| 76 | + throw error; | ||
| 77 | + } | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +/** | ||
| 81 | + * Event listener for HTTP server "listening" event. | ||
| 82 | + */ | ||
| 83 | + | ||
| 84 | +function onListening() { | ||
| 85 | + var addr = server.address(); | ||
| 86 | + var bind = typeof addr === 'string' | ||
| 87 | + ? 'pipe ' + addr | ||
| 88 | + : 'port ' + addr.port; | ||
| 89 | + debug('Listening on ' + bind); | ||
| 90 | +} |
createBucket.js
0 → 100644
| 1 | +const AWS = require('aws-sdk'); | ||
| 2 | +const ID = 'id'; | ||
| 3 | +const SECRET = 'secret'; | ||
| 4 | + | ||
| 5 | +const BUCKET_NAME = 'dogpicture-dizzi'; | ||
| 6 | + | ||
| 7 | +const s3 = new AWS.S3 ({ | ||
| 8 | + accessKeyId: ID, | ||
| 9 | + secretAccessKey:SECRET | ||
| 10 | +}); | ||
| 11 | + | ||
| 12 | +const params = { | ||
| 13 | + Bucket: BUCKET_NAME, | ||
| 14 | + CreateBucketConfiguration: { | ||
| 15 | + //Set your regieon here | ||
| 16 | + LocationConstraint : "us-east-1" | ||
| 17 | + } | ||
| 18 | +}; | ||
| 19 | + | ||
| 20 | +s3.createBucket(params, function(err, data) { | ||
| 21 | + if (err) console.log(err, err.stack); | ||
| 22 | + else console.log('Bucket Created Successfully', data.Location); | ||
| 23 | +}); | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
package-lock copy.json
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
package.json
deleted
100644 → 0
| 1 | -{ | ||
| 2 | - "name": "oss-project", | ||
| 3 | - "version": "1.0.0", | ||
| 4 | - "description": "KindOfYourDog", | ||
| 5 | - "main": "app.js", | ||
| 6 | - "dependencies": { | ||
| 7 | - "aws-sdk": "^2.689.0", | ||
| 8 | - "express": "^4.17.1" | ||
| 9 | - }, | ||
| 10 | - "devDependencies": {}, | ||
| 11 | - "scripts": { | ||
| 12 | - "test": "echo \"Error: no test specified\" && exit 1", | ||
| 13 | - "start":"node app.js" | ||
| 14 | - }, | ||
| 15 | - "repository": { | ||
| 16 | - "type": "git", | ||
| 17 | - "url": "ssh://git@khuhub.khu.ac.kr:12959/2016101156/OSS-Project.git" | ||
| 18 | - }, | ||
| 19 | - "author": "", | ||
| 20 | - "license": "ISC" | ||
| 21 | -} |
public/stylesheets/style.css
0 → 100644
routes/index.js
0 → 100644
routes/users.js
0 → 100644
views/error.ejs
0 → 100644
-
Please register or login to post a comment