forked from mother/react-files
-
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.
Updated demo to handle file uploading
- Loading branch information
Showing
7 changed files
with
71 additions
and
15 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
node_modules | ||
npm-debug.log | ||
.uploads/* |
File renamed without changes.
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
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
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 |
---|---|---|
@@ -1,14 +1,52 @@ | ||
var express = require('express') | ||
var fs = require('fs') | ||
var multer = require('multer') | ||
var path = require('path') | ||
|
||
var webpack = require('webpack') | ||
var WebpackDevServer = require('webpack-dev-server') | ||
var webpackDevMiddleware = require('webpack-dev-middleware') | ||
var webpackHotMiddleware = require('webpack-hot-middleware') | ||
var config = require('./webpack.dev.config') | ||
var compiler = webpack(config) | ||
|
||
var app = express() | ||
var upload = multer({ dest: './.uploads/' }) | ||
|
||
app.use(webpackDevMiddleware(compiler, { | ||
publicPath: config.output.publicPath, | ||
noInfo: true, | ||
quiet: false, | ||
historyApiFallback: true, | ||
stats: { | ||
colors: true | ||
} | ||
})) | ||
|
||
app.use(webpackHotMiddleware(compiler, { | ||
log: console.log, | ||
path: '/__webpack_hmr', | ||
heartbeat: 10 * 1000 | ||
})) | ||
|
||
app.use('/assets', express.static('assets')) | ||
|
||
app.get('/', function (req, res, next) { | ||
res.sendFile(path.join(__dirname + '/index.html')); | ||
}) | ||
|
||
app.post('/files', upload.any(), function (req, res, next) { | ||
if (!req.files) { | ||
return next(new Error('No files uploaded')) | ||
} | ||
|
||
req.files.forEach((file) => { | ||
console.log(file) | ||
fs.unlinkSync(path.join(__dirname, file.path)) | ||
}) | ||
|
||
res.status(200).end() | ||
}) | ||
|
||
new WebpackDevServer(webpack(config), { | ||
publicPath: config.output.publicPath, | ||
hot: true, | ||
historyApiFallback: true | ||
}).listen(8080, 'localhost', function (err, result) { | ||
if (err) { | ||
return console.log(err) | ||
} | ||
console.log('Listening at http://localhost:8080/') | ||
app.listen(8080, function () { | ||
console.log(`Starting react-files demo on port 8080`) | ||
}) |
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
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