Skip to content

Commit 7d7ba8b

Browse files
committed
initial commit
0 parents  commit 7d7ba8b

40 files changed

+1024
-0
lines changed

.gitignore

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.trails
2+
.tmp
3+
4+
# Local
5+
config/local.js
6+
7+
# Logs
8+
logs
9+
*.log
10+
11+
# Runtime data
12+
pids
13+
*.pid
14+
*.seed
15+
16+
# Directory for instrumented libs generated by jscoverage/JSCover
17+
lib-cov
18+
19+
# Coverage directory used by tools like istanbul
20+
coverage
21+
22+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
23+
.grunt
24+
25+
# node-waf configuration
26+
.lock-wscript
27+
28+
# Compiled binary addons (http://nodejs.org/api/addons.html)
29+
build/Release
30+
31+
# Dependency directory
32+
node_modules
33+
34+
# Documentation folder
35+
docs
36+
37+
# Miscellaneous
38+
*~
39+
*#
40+
.DS_STORE
41+
.netbeans
42+
nbproject
43+
.idea
44+
.node_history
45+
.tmp
46+
*.sw*
47+
package-lock.json

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# <%= answers['app:name'] %>
2+
3+
[![NPM version][npm-image]][npm-url]
4+
[![Build status][ci-image]][ci-url]
5+
[![Dependency Status][daviddm-image]][daviddm-url]
6+
[![Code Climate][codeclimate-image]][codeclimate-url]
7+
8+
<%= answers['app:desc'] %>
9+
10+
## License
11+
MIT
12+
13+
[npm-image]: https://img.shields.io/npm/v/<%= answers['app:name'] %>.svg?style=flat-square
14+
[npm-url]: https://npmjs.org/package/<%= answers['app:name'] %>
15+
[ci-image]: https://img.shields.io/travis/trailsjs/<%= answers['app:name'] %>/master.svg?style=flat-square
16+
[ci-url]: https://travis-ci.org/trailsjs/<%= answers['app:name'] %>
17+
[daviddm-image]: http://img.shields.io/david/trailsjs/<%= answers['app:name'] %>.svg?style=flat-square
18+
[daviddm-url]: https://david-dm.org/trailsjs/<%= answers['app:name'] %>
19+
[codeclimate-image]: https://img.shields.io/codeclimate/github/trailsjs/<%= answers['app:name'] %>.svg?style=flat-square
20+
[codeclimate-url]: https://codeclimate.com/github/trailsjs/<%= answers['app:name'] %>

api/controllers/DefaultController.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict'
2+
3+
const Controller = require('trails/controller')
4+
5+
/**
6+
* @module DefaultController
7+
*
8+
* @description Default Controller included with a new Trails app
9+
* @see {@link http://trailsjs.io/doc/api/controllers}
10+
* @this TrailsApp
11+
*/
12+
module.exports = class DefaultController extends Controller {
13+
14+
/**
15+
* Return some info about this application
16+
*/
17+
info(req, res) {
18+
res.status(200).json(this.app.services.DefaultService.getApplicationInfo())
19+
}
20+
}

api/controllers/SocketController.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict'
2+
3+
const Controller = require('trails/controller')
4+
const jwt = require('jsonwebtoken')
5+
6+
/**
7+
* @module SocketController
8+
* @description socket controller.
9+
*/
10+
module.exports = class SocketController extends Controller {
11+
12+
home(req, res) {
13+
return res.sendFile('login.html', {root: './public'});
14+
}
15+
16+
login(req,res){
17+
18+
let model = req.body
19+
if(!model || ! model.username) return res.send('Invalid credential')
20+
21+
model.name = model.username
22+
let token = jwt.sign(model, 'jsbot', { expiresIn: 60*60*5 })
23+
24+
// res.cookie('sock_token', token, { expires: new Date(Date.now() + 900000) })
25+
res.json({ token })
26+
}
27+
28+
chat(req,res){
29+
return res.sendFile('chat.html', {root: './public'});
30+
}
31+
32+
group(req,res){
33+
return res.sendFile('group.html', {root: './public'});
34+
}
35+
}
36+

api/controllers/ViewController.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict'
2+
3+
const Controller = require('trails/controller')
4+
5+
module.exports = class ViewController extends Controller {
6+
helloWorld(req, res) {
7+
res.status(200).send('Hello Trails.js !')
8+
}
9+
}

api/controllers/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
exports.DefaultController = require('./DefaultController')
4+
exports.ViewController = require('./ViewController')
5+
exports.SocketController = require('./SocketController')

api/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict'
2+
3+
exports.controllers = require('./controllers')
4+
exports.models = require('./models')
5+
exports.policies = require('./policies')
6+
exports.services = require('./services')

api/models/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'use strict'

api/policies/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'use strict'

api/services/DefaultService.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict'
2+
3+
const Service = require('trails/service')
4+
5+
/**
6+
* @module DefaultService
7+
*
8+
* @description Default Service included with a new Trails app
9+
* @see {@link http://trailsjs.io/doc/api/services}
10+
* @this TrailsApp
11+
*/
12+
module.exports = class DefaultService extends Service {
13+
14+
/**
15+
* Return some info about this application
16+
*/
17+
getApplicationInfo() {
18+
const trailpacks = []
19+
Object.keys(this.app.packs).forEach(packName => {
20+
if (packName != 'inspect') {
21+
const pack = this.app.packs[packName]
22+
trailpacks.push({
23+
name: pack.name,
24+
version: pack.pkg.version
25+
})
26+
}
27+
})
28+
return {
29+
app: this.app.pkg.version,
30+
node: process.version,
31+
libs: process.versions,
32+
trailpacks: trailpacks
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)