summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..3bebc43
--- /dev/null
+++ b/index.js
@@ -0,0 +1,66 @@
+
+require('dotenv').load()
+
+var fs = require('fs')
+var app, express = require('express')
+var http = require('http')
+var bodyParser = require('body-parser')
+var path = require('path')
+
+var multer = require('multer')
+var upload = multer({ dest: 'uploads/' })
+
+var app, server
+
+const db = require('./lib/db')
+
+var site = module.exports = {}
+site.init = function(){
+ app = express()
+ app.use(express.static(path.join(__dirname, './public')))
+ app.use(bodyParser.json())
+ app.use(bodyParser.urlencoded({ extended: false }))
+
+ app.use(express.query())
+
+ server = http.createServer(app).listen(process.env.PORT, function () {
+ console.log('Cortex listening at http://localhost:%s', server.address().port)
+ })
+
+// app.get("/p/:id", function(req, res){
+// res.sendFile("index.html", {root: './public'})
+// })
+// app.get("/get/random", function(req, res){
+// db.getRandom().then(function(img){
+// res.json(img)
+// })
+// })
+// app.get("/get/latest", function(req, res){
+// db.getLatest().then(function(img){
+// res.json(img)
+// })
+// })
+// app.get("/get/:id/hotlink", function(req, res){
+// db.getImage(req.params.id).then(function(img){
+// res.redirect(img.url)
+// })
+// })
+// app.get("/get/:id", function(req, res){
+// db.getImage(req.params.id).then(function(img){
+// res.json(img)
+// })
+// })
+
+ app.post("/upload", upload.single('image'), function(req, res){
+ upload.put("image", req.file, {
+ unacceptable: function(err){
+ res.json({ error: err })
+ },
+ success: function(url){
+ db.createImage(url).then(function(image){
+ res.json(image)
+ })
+ }
+ })
+ })
+}