Last active
April 25, 2018 19:04
-
-
Save doron2402/d0d31d5bb86cf99fd506fcf4cf501daa to your computer and use it in GitHub Desktop.
Simple upload server using single dependecy
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
'use strict'; | |
/** | |
For full repo go to: | |
https://github.com/doron2402/simple-upload-files | |
**/ | |
const http = require('http'); | |
const uploaderRoute = require('./routes/uploader'); | |
const formRoute = require('./routes/form'); | |
const notFoundRoute = require('./routes/notFound'); | |
const PORT = 3000; | |
http.createServer(function (req, res) { | |
if (req.url.toLowerCase() === '/upload' && req.method.toLowerCase() === 'post') { | |
return uploaderRoute(req, res); | |
} | |
else if (req.url.toLowerCase() === '/form' && req.method.toLowerCase() === 'get') { | |
return formRoute(req, res); | |
} | |
else { | |
return notFoundRoute(req, res); | |
} | |
}).listen(PORT, (err) => { | |
if (err) { | |
throw err; | |
} | |
console.log(`Server is running ${PORT}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
starting...