123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- var express = require('express');
- var app = express();
- var UserManager = require("./users");
- var Response = require("./Response");
- var multer = require("multer");
- var path = require("path");
- var crypto = require("crypto");
- var mime = require("mime");
- var Server = require("./Server");
- var utils = require("./utils");
- var upload = multer({
- dest: 'tmp/' // this saves your file into a directory called "uploads"
- });
- var bodyParser = require('body-parser')
- app.use( bodyParser.json() ); // to support JSON-encoded bodies
- app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
- extended: true
- }));
- const prefix = "";
- const apiprefix = prefix+"/api";
- const appprefix = prefix+"/app";
- var server = new Server();
- var storage = multer.diskStorage({
- destination: function(req, file, cb) {
- cb(null, 'tmp/')
- },
- filename: function(req, file, cb) {
- crypto.pseudoRandomBytes(16, function(err, raw) {
- cb(null, raw.toString('hex') + Date.now() + '.' + mime.extension(file.mimetype));
- });
- }
- });
- var upload = multer({
- storage: storage
- });
- var userList = new UserManager();
- //users
- app.get(apiprefix+'/createUser', function (a, b) {server.createUser(a, b)});
- app.get(apiprefix+'/users', function (a, b) {server.listUsers(a, b)});
- app.get(apiprefix+'/user/:user', function (a, b) {server.serveUser(a, b)});
- app.post(apiprefix+'/createUser', function (a, b) {server.createUser(a, b)});
- app.post(apiprefix+'/users', function (a, b) {server.listUsers(a, b)});
- app.post(apiprefix+'/user/:user', function (a, b) {server.serveUser(a, b)});
- app.post(apiprefix+'/user/:user/edit', function (a, b) {server.editUser(a, b)});
- app.get(apiprefix+'/user/:user/rename', function (a, b) {server.renameUser(a, b)});
- app.post(apiprefix+'/user/:user/rename', function (a, b) {server.renameUser(a, b)});
- app.get(apiprefix+'/user/:user/remove', function (a, b) {server.removeUser(a, b)});
- app.post(apiprefix+'/user/:user/remove', function (a, b) {server.removeUser(a, b)});
- //Projects
- app.get(apiprefix+'/user/:user/createProject', function (a, b) {console.log("_1"); server.createProject(a, b)});
- app.get(apiprefix+'/user/:user/projects', function (a, b) {server.listProjects(a, b)});
- app.get(apiprefix+'/user/:user/:project', function (a, b) { server.serveProject(a, b)});
- app.post(apiprefix+'/user/:user/:project/edit', function (a, b) {server.editProject(a, b)});
- app.get(apiprefix+'/user/:user/:project/rename', function (a, b) {server.renameProject(a, b)});
- app.post(apiprefix+'/user/:user/:project/rename', function (a, b) {server.renameProject(a, b)});
- app.get(apiprefix+'/user/:user/:project/remove', function (a, b) {server.removeProject(a, b)});
- app.post(apiprefix+'/user/:user/:project/remove', function (a, b) {server.removeProject(a, b)});
- //resources
- app.get(apiprefix+'/user/:user/:project/createResource', function (a, b) {console.log("_1"); server.createResource(a, b)});
- app.get(apiprefix+'/user/:user/:project/resources', function (a, b) {server.listResources(a, b)});
- app.get(apiprefix+'/user/:user/:project/:res', function (a, b) { server.serveResource(a, b)});
- app.post(apiprefix+'/user/:user/:project/:res/edit', function (a, b) {server.editRescource(a, b)});
- app.get(apiprefix+'/user/:user/:project/:res/rename', function (a, b) {server.renameResource(a, b)});
- app.post(apiprefix+'/user/:user/:project/:res/rename', function (a, b) {server.renameResource(a, b)});
- app.get(apiprefix+'/user/:user/:project/:res/remove', function (a, b) {server.removeResource(a, b)});
- app.post(apiprefix+'/user/:user/:project/:res/remove', function (a, b) {server.removeResource(a, b)});
- /*
- app.post(apiprefix+'/user/:user/:project/:resource', upload.single("image"), function(req, res) {
- res.send('<img src="'+apiprefix+'/upload/' + req.file.filename + '" />');
- });
- app.get(apiprefix+'/upload/:file', function(req, res) {
- res.sendFile(path.join(__dirname + '/tmp/'+req.params.file));
- });
- app.get(appprefix+'/:file', function (req, res) {
- res.sendFile(path.join(__dirname + '/../www/'+req.params.file));
- });
- app.get(apiprefix+'/user/:name', function (req, res) { server.serveUser(req, res);});*/
- var rest = app.listen(8081, function () {
- var host = rest.address().address
- var port = rest.address().port
- console.log("Example app listening at http://%s:%s", host, port)
- })
|