Skip to content

Commit

Permalink
dobuyshop
Browse files Browse the repository at this point in the history
  • Loading branch information
kyjin8 committed Sep 3, 2021
0 parents commit 89663ab
Show file tree
Hide file tree
Showing 141 changed files with 207,425 additions and 0 deletions.
109 changes: 109 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const createError = require('http-errors');
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const engines = require('consolidate');
const multer = require('multer');
const multiparty = require('multiparty');
const fs = require('fs');

// const storage = multer.diskStorage({ // 2
// destination(req, file, cb) {
// cb(null, 'uploadedFiles/');
// },
// filename(req, file, cb) {
// cb(null, `${file.originalname}`);
// },
// });
// const upload = multer({dest : "public/images/"});
// var uploadWithOriginalFilename = multer({ storage: storage });

const app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.engine('html', engines.mustache);
app.set('view engine', 'html');

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(express.static(path.join(__dirname, 'build/contracts')));

app.get('/', function(req, res, next) {
res.render('index');
});

app.get('/market', function(req, res, next) {
res.render('market');
});

app.get('/mypage', function(req, res, next) {
res.render('mypage');
});

app.get('/trade', function(req, res, next) {
res.render('trade');
});

app.get('/swap', function(req, res, next) {
res.render('swap');
});

app.post('/upload', function(req, res, next) {
var form = new multiparty.Form();
form.on('field', function(name, value){
console.log(name, ' : ', value);
});
form.on('part', function(part) {
var filename;
var size;
if(part.filename) {
filename = part.filename;
size = part.size;
}else {
part.resume();
}

console.log("Write Streaming file : " + filename);
var writeStream = fs.createWriteStream('public/images/'+filename);
writeStream.filename = filename;
part.pipe(writeStream);

part.on('data',function(chunk){
console.log(filename+' read '+chunk.length + 'bytes');
});
part.on('end',function(){
console.log(filename+' Part read complete');
writeStream.end();
});
});
form.on('close',function(){
res.status(200).send('Upload complete');
});
form.on('progress',function(byteRead,byteExpected){
console.log(' Reading total '+byteRead+'/'+byteExpected);
});
form.parse(req);
});

// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});

module.exports = app;
90 changes: 90 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

const app = require('../app');
const debug = require('debug')('dobuyshop:server');
const http = require('http');

/**
* Get port from environment and store in Express.
*/

const port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

const 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) {
const 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;
}

const 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() {
const addr = server.address();
const bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
6 changes: 6 additions & 0 deletions bs-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"server": {
"baseDir": ["./views", "./build/contracts", "./public"]
}
}

Loading

0 comments on commit 89663ab

Please sign in to comment.