forked from nodester/nodester
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
126 lines (96 loc) · 4.64 KB
/
Copy pathapp.js
File metadata and controls
126 lines (96 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
Nodester opensource Node.js hosting service
Written by: @ChrisMatthieu & @DanBUK
http://nodester.com
*/
var express = require('express'),
url = require('url'),
sys = require('sys'),
config = require('./config'),
middle = require('./lib/middle');
process.on('uncaughtException', function (err) {
console.log(err.stack);
});
var myapp = express.createServer();
myapp.configure(function(){
myapp.use(express.bodyDecoder());
myapp.use(express.staticProvider(config.opt.public_html_dir));
myapp.use(middle.error());
});
// Routes
// Homepage
myapp.get('/', function(req, res, next){
res.render('index.html');
});
// Status API
// http://localhost:4001/status
// curl http://localhost:4001/status
var status = require('./lib/status');
myapp.get('/status', status.get);
// New coupon request
// curl -X POST -d "email=dan@nodester.com" http://localhost:4001/coupon
var coupon = require('./lib/coupon');
myapp.post('/coupon', coupon.post);
// curl http://localhost:4001/unsent
myapp.get('/unsent', coupon.unsent);
// New user account registration
// curl -X POST -d "user=testuser&password=123&email=chris@nodefu.com&coupon=hiyah" http://localhost:4001/user
// curl -X POST -d "user=me&password=123&coupon=hiyah" http://localhost:4001/user
var user = require('./lib/user');
myapp.post('/user', user.post);
// localhost requires basic auth to access this section
// Edit your user account
// curl -X PUT -u "testuser:123" -d "password=test&rsakey=1234567" http://localhost:4001/user
myapp.put('/user', middle.authenticate, user.put);
// Delete your user account
// curl -X DELETE -u "testuser:123" http://localhost:4001/user
myapp.delete('/user', middle.authenticate, user.delete);
// All Applications info
// http://chris:123@localhost:4001/apps
// curl -u "testuser:123" http://localhost:4001/apps
var apps = require('./lib/apps');
myapp.get('/apps', middle.authenticate, apps.get);
var app = require('./lib/app');
// Application info
// http://chris:123@localhost:4001/app/<appname>
// curl -u "testuser:123" http://localhost:4001/app/<appname>
myapp.get('/app/:appname', middle.authenticate, middle.authenticate_app, app.get);
// Create node app
// curl -X POST -u "testuser:123" -d "appname=test&start=hello.js" http://localhost:4001/apps
myapp.post('/app', middle.authenticate, app.post);
// App backend restart handler
myapp.get('/app_restart', app.app_restart);
myapp.get('/app_start', app.app_start);
myapp.get('/app_stop', app.app_stop);
// Update node app
// start=hello.js - To update the initial run script
// running=true - To Start the app
// running=false - To Stop the app
// curl -X PUT -u "testuser:123" -d "appname=test&start=hello.js" http://localhost:4001/app
// curl -X PUT -u "testuser:123" -d "appname=test&running=true" http://localhost:4001/app
// curl -X PUT -u "testuser:123" -d "appname=test&running=false" http://localhost:4001/app
// curl -X PUT -u "testuser:123" -d "appname=test&running=restart" http://localhost:4001/app
// TODO - Fix this function, it's not doing callbacking properly so will return JSON in the wrong state!
myapp.put('/app', middle.authenticate, middle.authenticate_app, app.put);
// Delete your nodejs app
// curl -X DELETE -u "testuser:123" -d "appname=test" http://localhost:4001/apps
myapp.delete('/app', middle.authenticate, middle.authenticate_app, app.delete);
myapp.delete('/gitreset', middle.authenticate, middle.authenticate_app, app.gitreset);
// curl -u "testuser:123" -d "appname=test" http://localhost:4001/applogs
myapp.get('/applogs/:appname', middle.authenticate, middle.authenticate_app, app.logs);
// APP NPM Handlers
var npm = require('./lib/npm');
// curl -X POST -u "testuser:123" -d "appname=test&package=express" http://localhost:4001/appnpm
// curl -X POST -u "testuser:123" -d "appname=test&package=express" http://localhost:4001/npm
// curl -X POST -u "testuser:123" -d "appname=test&package=express,express-extras,foo" http://localhost:4001/npm
myapp.post('/appnpm', middle.authenticate, middle.authenticate_app, npm.post);
myapp.post('/npm', middle.authenticate, middle.authenticate_app, npm.post);
// curl -X POST -u "testuser:123" -d "appname=test&domain=<domainname>" http://localhost:4001/appdomains
// curl -X DELETE -u "testuser:123" -d "appname=test&domain=<domainname>" http://localhost:4001/appdomains
var domains = require('./lib/domains');
myapp.post('/appdomains', middle.authenticate, middle.authenticate_app, domains.post);
myapp.delete('/appdomains', middle.authenticate, middle.authenticate_app, domains.delete);
myapp.get('/appdomains', middle.authenticate, domains.get);
myapp.use(express.errorHandler({ showStack: true }));
myapp.listen(4001);
console.log('Nodester app started on port 4001');