Skip to content

Instantly share code, notes, and snippets.

@hyperh
hyperh / apnagent.js
Created May 20, 2016 05:57
apnagent setup
import apnagent from 'apnagent';
let agent = new apnagent.Agent();
agent
.set('cert', Assets.getText('cert.pem'))
.set('key', Assets.getText('key.pem'))
.enable('sandbox')
.connect(function (err) {
if (err) {
@hyperh
hyperh / sendAPN.js
Last active May 20, 2016 06:48
Sending an APN from Meteor server
import _ from 'lodash';
const SEND_APN_MSG = 'notifications.send.APNMsg';
Meteor.methods({
'notifications.send.APNMsg'({sendToUserId}) {
check(arguments[0], {
sendToUserId: String,
});
const user = Meteor.users.findOne(sendToUserId);
@hyperh
hyperh / react-native-push-notification.js
Last active May 20, 2016 06:32
Setting up react-native-push-notification
import React from 'react-native';
import PushNotification from 'react-native-push-notification';
export default function () {
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister(data) {
Meteor.call('notifications.set.pushToken', {data}, err => {
if (err) { alert(`notifications.set.pushToken: ${err.reason}`); }
});
@hyperh
hyperh / set-token.js
Last active May 20, 2016 06:37
Setting device-specific push notification token
const SET_PUSH_TOKEN = 'notifications.set.pushToken';
Meteor.methods({
'notifications.set.pushToken'({token, os}) {
check(arguments[0], {
token: String,
os: String,
});
const userId = this.userId;
if (!userId) {
{
"presets": [
"es2015",
"react",
"stage-0"
]
}
import React, { Component } from 'react';
export default class App extends Component {
render() {
return (
<div>
Hello world!
</div>
);
}
export default ({ body, title }) => {
return `
<!DOCTYPE html>
<html>
<head>
<title>${title}</title>
</head>
<body>
<div id="root">${body}</div>
import express from 'express';
import React from 'react';
import { renderToString } from 'react-dom/server';
import App from '../app/components/App';
import template from '../app/template';
const app = express();
app.get('/', (req, res) => {
const appString = renderToString(<App />);
const path = require('path');
const nodeExternals = require('webpack-node-externals');
module.exports = {
name: 'SSR',
entry: './app/SSR.js',
output: {
path: path.join(__dirname, '.', 'dist', 'assets'),
filename: 'SSR.js',
libraryTarget: 'commonjs2',
import React from 'react';
import { renderToString } from 'react-dom/server';
import template from './template';
import App from './components/App';
export default function render(req, res) {
const appString = renderToString(<App />);
res.send(template({
body: appString,
title: 'FROM THE SERVER',