├── .editorconfig
├── .gitignore
├── .jshintrc
├── .npmignore
├── Dockerfile
├── LICENSE
├── README.md
├── config
├── default.json
└── production.json
├── package.json
├── public
├── favicon.ico
└── index.html
├── src
├── app.js
├── hooks
│ └── index.js
├── index.js
├── middleware
│ ├── index.js
│ ├── logger.js
│ └── not-found-handler.js
└── services
│ ├── index.js
│ └── message
│ ├── hooks
│ └── index.js
│ ├── index.js
│ └── message-model.js
└── test
├── app.test.js
└── services
└── message
└── index.test.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | # http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
12 | [*.md]
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # Runtime data
6 | pids
7 | *.pid
8 | *.seed
9 |
10 | # Directory for instrumented libs generated by jscoverage/JSCover
11 | lib-cov
12 |
13 | # Coverage directory used by tools like istanbul
14 | coverage
15 |
16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17 | .grunt
18 |
19 | # Compiled binary addons (http://nodejs.org/api/addons.html)
20 | build/Release
21 |
22 | # Dependency directory
23 | # Commenting this out is preferred by some people, see
24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
25 | node_modules
26 |
27 | # Users Environment Variables
28 | .lock-wscript
29 |
30 | lib/
31 | data/
32 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "node": true,
3 | "esnext": true,
4 | "bitwise": true,
5 | "camelcase": true,
6 | "curly": true,
7 | "eqeqeq": true,
8 | "immed": true,
9 | "indent": 2,
10 | "latedef": "nofunc",
11 | "newcap": false,
12 | "noarg": true,
13 | "quotmark": "single",
14 | "regexp": true,
15 | "undef": true,
16 | "unused": false,
17 | "strict": false,
18 | "trailing": true,
19 | "smarttabs": true,
20 | "white": false,
21 | "globals": {
22 | "it": true,
23 | "describe": true,
24 | "before": true,
25 | "beforeEach": true,
26 | "after": true,
27 | "afterEach": true
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # Runtime data
6 | pids
7 | *.pid
8 | *.seed
9 |
10 | # Directory for instrumented libs generated by jscoverage/JSCover
11 | lib-cov
12 |
13 | # Coverage directory used by tools like istanbul
14 | coverage
15 |
16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17 | .grunt
18 |
19 | # Compiled binary addons (http://nodejs.org/api/addons.html)
20 | build/Release
21 |
22 | # Dependency directory
23 | # Commenting this out is preferred by some people, see
24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
25 | node_modules
26 |
27 | # Users Environment Variables
28 | .lock-wscript
29 |
30 | data/
31 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:6.2
2 |
3 | WORKDIR /home/feathers
4 | COPY README.md README.md
5 | COPY package.json package.json
6 | COPY config/ config/
7 | COPY public/ public/
8 | COPY src/ src/
9 | ENV NODE_ENV 'production'
10 | ENV PORT '8080'
11 | RUN npm install --production
12 | CMD ["node", "src/index.js"]
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Feathers
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # yycjs
2 |
3 | > docker for yyjc
4 |
5 | ## About
6 |
7 | This project uses [Feathers](http://feathersjs.com). An open source web framework for building modern real-time applications.
8 |
9 | ## Getting Started
10 |
11 | Getting up and running is as easy as 1, 2, 3.
12 |
13 | 1. Make sure you have [NodeJS](https://nodejs.org/) and [npm](https://www.npmjs.com/) installed.
14 | 2. Install your dependencies
15 |
16 | ```
17 | cd path/to/yycjs; npm install
18 | ```
19 |
20 | 3. Start your app
21 |
22 | ```
23 | npm start
24 | ```
25 |
26 | ## Testing
27 |
28 | Simply run `npm test` and all your tests in the `test/` directory will be run.
29 |
30 | ## Scaffolding
31 |
32 | Feathers has a powerful command line interface. Here are a few things it can do:
33 |
34 | ```
35 | $ npm install -g feathers-cli # Install Feathers CLI
36 |
37 | $ feathers generate service # Generate a new Service
38 | $ feathers generate hook # Generate a new Hook
39 | $ feathers generate model # Generate a new Model
40 | $ feathers help # Show all commands
41 | ```
42 |
43 | ## Help
44 |
45 | For more information on all the things you can do with Feathers visit [docs.feathersjs.com](http://docs.feathersjs.com).
46 |
47 | ## Changelog
48 |
49 | __0.1.0__
50 |
51 | - Initial release
52 |
53 | ## License
54 |
55 | Copyright (c) 2016
56 |
57 | Licensed under the [MIT license](LICENSE).
58 |
--------------------------------------------------------------------------------
/config/default.json:
--------------------------------------------------------------------------------
1 | {
2 | "host": "localhost",
3 | "port": 3030,
4 | "mongodb": "mongodb://localhost:27017/yycjs",
5 | "public": "../public/"
6 | }
7 |
--------------------------------------------------------------------------------
/config/production.json:
--------------------------------------------------------------------------------
1 | {
2 | "host": "yycjs-app.feathersjs.com",
3 | "port": 8080,
4 | "mongodb": "MONGO_PORT_27017_TCP",
5 | "public": "../public/"
6 | }
7 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "yycjs",
3 | "description": "docker for yyjc",
4 | "version": "0.0.0",
5 | "homepage": "",
6 | "main": "src/",
7 | "keywords": [
8 | "feathers"
9 | ],
10 | "license": "MIT",
11 | "repository": {},
12 | "author": {},
13 | "contributors": [],
14 | "bugs": {},
15 | "engines": {
16 | "node": ">= 0.12.0"
17 | },
18 | "scripts": {
19 | "test": "npm run jshint && npm run mocha",
20 | "jshint": "jshint src/. test/. --config",
21 | "start": "node src/",
22 | "mocha": "mocha test/ --recursive"
23 | },
24 | "dependencies": {
25 | "body-parser": "^1.15.2",
26 | "compression": "^1.6.2",
27 | "cors": "^2.7.1",
28 | "feathers": "^2.0.1",
29 | "feathers-configuration": "^0.2.3",
30 | "feathers-errors": "^2.2.0",
31 | "feathers-hooks": "^1.5.4",
32 | "feathers-mongoose": "^3.4.1",
33 | "feathers-rest": "^1.4.2",
34 | "feathers-socketio": "^1.4.1",
35 | "mongoose": "^4.5.1",
36 | "serve-favicon": "^2.3.0",
37 | "winston": "^2.2.0"
38 | },
39 | "devDependencies": {
40 | "jshint": "^2.9.2",
41 | "mocha": "^2.5.3",
42 | "request": "^2.72.0"
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yycjs/feathers-docker/3703bec77b4c0f5d9254c62413140235a733740a/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Welcome to Feathers
4 |
62 |
63 |
64 |
65 |
66 | A minimalist real-time app eco-system for tomorrow's apps.
67 |
68 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/src/app.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const path = require('path');
4 | const serveStatic = require('feathers').static;
5 | const favicon = require('serve-favicon');
6 | const compress = require('compression');
7 | const cors = require('cors');
8 | const feathers = require('feathers');
9 | const configuration = require('feathers-configuration');
10 | const hooks = require('feathers-hooks');
11 | const rest = require('feathers-rest');
12 | const bodyParser = require('body-parser');
13 | const socketio = require('feathers-socketio');
14 | const middleware = require('./middleware');
15 | const services = require('./services');
16 |
17 | const app = feathers();
18 |
19 | app.configure(configuration(path.join(__dirname, '..')));
20 |
21 | app.use(compress())
22 | .options('*', cors())
23 | .use(cors())
24 | .use(favicon( path.join(app.get('public'), 'favicon.ico') ))
25 | .use('/', serveStatic( app.get('public') ))
26 | .use(bodyParser.json())
27 | .use(bodyParser.urlencoded({ extended: true }))
28 | .configure(hooks())
29 | .configure(rest())
30 | .configure(socketio())
31 | .configure(services)
32 | .configure(middleware);
33 |
34 | module.exports = app;
35 |
--------------------------------------------------------------------------------
/src/hooks/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // Add any common hooks you want to share across services in here.
4 | //
5 | // Below is an example of how a hook is written and exported. Please
6 | // see http://docs.feathersjs.com/hooks/readme.html for more details
7 | // on hooks.
8 |
9 | exports.myHook = function(options) {
10 | return function(hook) {
11 | console.log('My custom global hook ran. Feathers is awesome!');
12 | };
13 | };
14 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const app = require('./app');
4 | const port = app.get('port');
5 | const server = app.listen(port);
6 |
7 | server.on('listening', () =>
8 | console.log(`Feathers application started on ${app.get('host')}:${port}`)
9 | );
--------------------------------------------------------------------------------
/src/middleware/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const handler = require('feathers-errors/handler');
4 | const notFound = require('./not-found-handler');
5 | const logger = require('./logger');
6 |
7 | module.exports = function() {
8 | // Add your custom middleware here. Remember, that
9 | // just like Express the order matters, so error
10 | // handling middleware should go last.
11 | const app = this;
12 |
13 | app.use(notFound());
14 | app.use(logger(app));
15 | app.use(handler());
16 | };
17 |
--------------------------------------------------------------------------------
/src/middleware/logger.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const winston = require('winston');
4 |
5 | module.exports = function(app) {
6 | // Add a logger to our app object for convenience
7 | app.logger = winston;
8 |
9 | return function(error, req, res, next) {
10 | if (error) {
11 | const message = `${error.code ? `(${error.code}) ` : '' }Route: ${req.url} - ${error.message}`;
12 |
13 | if (error.code === 404) {
14 | winston.info(message);
15 | }
16 | else {
17 | winston.error(message);
18 | winston.info(error.stack);
19 | }
20 | }
21 |
22 | next(error);
23 | };
24 | };
25 |
--------------------------------------------------------------------------------
/src/middleware/not-found-handler.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const errors = require('feathers-errors');
4 |
5 | module.exports = function() {
6 | return function(req, res, next) {
7 | next(new errors.NotFound('Page not found'));
8 | };
9 | };
10 |
--------------------------------------------------------------------------------
/src/services/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const message = require('./message');
4 |
5 | const mongoose = require('mongoose');
6 | module.exports = function() {
7 | const app = this;
8 |
9 | mongoose.connect(app.get('mongodb').replace('tcp', 'mongodb'));
10 | mongoose.Promise = global.Promise;
11 |
12 | app.configure(message);
13 | };
14 |
--------------------------------------------------------------------------------
/src/services/message/hooks/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const globalHooks = require('../../../hooks');
4 | const hooks = require('feathers-hooks');
5 |
6 |
7 | exports.before = {
8 | all: [],
9 | find: [],
10 | get: [],
11 | create: [],
12 | update: [],
13 | patch: [],
14 | remove: []
15 | };
16 |
17 | exports.after = {
18 | all: [],
19 | find: [],
20 | get: [],
21 | create: [],
22 | update: [],
23 | patch: [],
24 | remove: []
25 | };
26 |
--------------------------------------------------------------------------------
/src/services/message/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const service = require('feathers-mongoose');
4 | const message = require('./message-model');
5 | const hooks = require('./hooks');
6 |
7 | module.exports = function() {
8 | const app = this;
9 |
10 | const options = {
11 | Model: message,
12 | paginate: {
13 | default: 5,
14 | max: 25
15 | }
16 | };
17 |
18 | // Initialize our service with any options it requires
19 | app.use('/messages', service(options));
20 |
21 | // Get our initialize service to that we can bind hooks
22 | const messageService = app.service('/messages');
23 |
24 | // Set up our before hooks
25 | messageService.before(hooks.before);
26 |
27 | // Set up our after hooks
28 | messageService.after(hooks.after);
29 | };
30 |
--------------------------------------------------------------------------------
/src/services/message/message-model.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // message-model.js - A mongoose model
4 | //
5 | // See http://mongoosejs.com/docs/models.html
6 | // for more of what you can do here.
7 |
8 | const mongoose = require('mongoose');
9 | const Schema = mongoose.Schema;
10 |
11 | const messageSchema = new Schema({
12 | text: { type: String, required: true },
13 | createdAt: { type: Date, 'default': Date.now },
14 | updatedAt: { type: Date, 'default': Date.now }
15 | });
16 |
17 | const messageModel = mongoose.model('message', messageSchema);
18 |
19 | module.exports = messageModel;
--------------------------------------------------------------------------------
/test/app.test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const assert = require('assert');
4 | const request = require('request');
5 | const app = require('../src/app');
6 |
7 | describe('Feathers application tests', function() {
8 | before(function(done) {
9 | this.server = app.listen(3030);
10 | this.server.once('listening', () => done());
11 | });
12 |
13 | after(function(done) {
14 | this.server.close(done);
15 | });
16 |
17 | it('starts and shows the index page', function(done) {
18 | request('http://localhost:3030', function(err, res, body) {
19 | assert.ok(body.indexOf('') !== -1);
20 | done(err);
21 | });
22 | });
23 |
24 | describe('404', function() {
25 | it('shows a 404 HTML page', function(done) {
26 | request({
27 | url: 'http://localhost:3030/path/to/nowhere',
28 | headers: {
29 | 'Accept': 'text/html'
30 | }
31 | }, function(err, res, body) {
32 | assert.equal(res.statusCode, 404);
33 | assert.ok(body.indexOf('') !== -1);
34 | done(err);
35 | });
36 | });
37 |
38 | it('shows a 404 JSON error without stack trace', function(done) {
39 | request({
40 | url: 'http://localhost:3030/path/to/nowhere',
41 | json: true
42 | }, function(err, res, body) {
43 | assert.equal(res.statusCode, 404);
44 | assert.equal(body.code, 404);
45 | assert.equal(body.message, 'Page not found');
46 | assert.equal(body.name, 'NotFound');
47 | done(err);
48 | });
49 | });
50 | });
51 | });
52 |
--------------------------------------------------------------------------------
/test/services/message/index.test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const assert = require('assert');
4 | const app = require('../../../src/app');
5 |
6 | describe('message service', function() {
7 | it('registered the messages service', () => {
8 | assert.ok(app.service('messages'));
9 | });
10 | });
11 |
--------------------------------------------------------------------------------