Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Kalveram committed Mar 5, 2018
0 parents commit 76ec4b3
Show file tree
Hide file tree
Showing 147 changed files with 20,345 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.swp

pids
logs
results
tmp

#Build
public/css/main.css

# API keys and secrets
.env

# Dependency directory
node_modules
bower_components

# Editors
.idea
*.iml

# OS metadata
.DS_Store
Thumbs.db
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:6-slim

COPY . /starter
COPY package.json /starter/package.json
COPY .env.example /starter/.env.example

WORKDIR /starter

ENV NODE_ENV production
RUN npm install --production

CMD ["npm","start"]

EXPOSE 8888
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014-2016 Sahat Yalkabov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
1,745 changes: 1,745 additions & 0 deletions README.md

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Module dependencies.
*/
const express = require('express');
const compression = require('compression');
const bodyParser = require('body-parser');
const logger = require('morgan');
const chalk = require('chalk');
const errorHandler = require('errorhandler');
const dotenv = require('dotenv');
const path = require('path');
const mongoose = require('mongoose');
const expressValidator = require('express-validator');
const expressStatusMonitor = require('express-status-monitor');
const sass = require('node-sass-middleware');

/**
* Load environment variables from .env file, where API keys and passwords are configured.
*/
dotenv.load({ path: '.env' });

/**
* Controllers (route handlers).
*/
const homeController = require('./controllers/home');
const apiController = require('./controllers/api');

/**
* Create Express server.
*/
const app = express();

/**
* Connect to MongoDB.
*/
mongoose.Promise = global.Promise;
mongoose.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI);
mongoose.connection.on('error', (err) => {
console.error(err);
console.log('%s MongoDB connection error. Please make sure MongoDB is running.', chalk.red('✗'));
process.exit();
});

/**
* Express configuration.
*/
app.set('host', process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0');
app.set('port', process.env.PORT || process.env.OPENSHIFT_NODEJS_PORT || 8080);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(expressStatusMonitor());
app.use(compression());
app.use(sass({
src: path.join(__dirname, 'public'),
dest: path.join(__dirname, 'public')
}));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(expressValidator());


/**
* Primary app routes.
*/
app.get('/', homeController.index);

/**
* API examples routes.
*/
app.get('/api', apiController.getApi);

/**
* Error Handler.
*/
app.use(errorHandler());

/**
* Start Express server.
*/
app.listen(app.get('port'), () => {
console.log('%s App is running at http://localhost:%d in %s mode', chalk.green('✓'), app.get('port'), app.get('env'));
console.log(' Press CTRL-C to stop\n');
});

module.exports = app;
36 changes: 36 additions & 0 deletions controllers/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const User = require('../models/User');

/**
* GET /api
* List of API examples.
*/
exports.getApi = (req, res) => {
const response = {
status: 'failure',
message: 'you didn\'t pass valid parameters'
};

if (!req.query || !req.query.token || !req.query.email || !req.query.name) {
return res.json(response);
}

const { email, name, token } = req.query;

const user = new User({
email,
name,
token
});

user.save((err) => {
if (err) {
response.message = 'couldn\'t save user, duplicate entry?';
return res.json(response);
}

response.status = 'success';
response.message = 'user successfully saved';

res.json(response);
});
};
12 changes: 12 additions & 0 deletions controllers/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const User = require('../models/User');

/**
* GET /
* Home page.
*/
exports.index = (req, res) => {
User.find((err, users) => {
res.render('home', { users });
});
};

18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '2'
services:
mongo:
image: mongo:3.4
web:
build: .
ports:
- "3000:3000"
environment:
- MONGODB_URI=mongodb://mongo:27017/expo-notifications
links:
- mongo
depends_on:
- mongo
volumes:
- .:/starter
- /starter/node_modules

11 changes: 11 additions & 0 deletions models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
email: { type: String, unique: true },
token: String,
name: String
}, { timestamps: true });

const User = mongoose.model('User', userSchema);

module.exports = User;
65 changes: 65 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "expo-push-notifications-server",
"version": "0.0.1",
"description": "A simple node server that exposes a basic API to save user tokens and lets you send notifications to them",
"repository": {
"type": "git",
"url": "https://github.com/marcelkalveram/expo-push-notifications-server"
},
"author": "Marcel Kalveram",
"license": "MIT",
"scripts": {
"start": "node app.js",
"test": "mocha --reporter spec",
"postinstall": "npm rebuild node-sass",
"eslint": "eslint **/*.js"
},
"dependencies": {
"body-parser": "^1.17.2",
"chalk": "^2.1.0",
"compression": "^1.7.0",
"dotenv": "^4.0.0",
"errorhandler": "^1.5.0",
"expo-server-sdk": "^2.3.3",
"express": "^4.15.4",
"express-status-monitor": "^1.0.0",
"express-validator": "^3.2.1",
"mongoose": "^4.11.7",
"morgan": "^1.8.2",
"node-sass-middleware": "^0.11.0",
"pug": "^2.0.0-rc.3"
},
"devDependencies": {
"chai": "^4.1.1",
"eslint": "^4.4.1",
"eslint-config-airbnb-base": "^11.3.1",
"eslint-plugin-chai-friendly": "^0.4.0",
"eslint-plugin-import": "^2.7.0",
"mocha": "^3.5.0",
"sinon": "^3.2.1",
"sinon-mongoose": "^2.0.2",
"supertest": "^3.0.0"
},
"eslintConfig": {
"extends": "airbnb-base",
"rules": {
"comma-dangle": 0,
"consistent-return": 0,
"no-param-reassign": 0,
"no-underscore-dangle": 0,
"no-shadow": 0,
"no-console": 0,
"no-plusplus": 0,
"no-unused-expressions": 0,
"chai-friendly/no-unused-expressions": 2
},
"env": {
"jasmine": true,
"mocha": true,
"node": true
},
"plugins": [
"chai-friendly"
]
}
}
Loading

0 comments on commit 76ec4b3

Please sign in to comment.