A Pen by Jack Scott on CodePen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = function (Frog) { | |
| /** | |
| * Helper functions can go here. | |
| */ | |
| Frog.uploadFrogImage = async (id, req) => { | |
| ... | |
| }; | |
| Frog.remoteMethod('uploadFrogImage', { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Frog.uploadFrogImage = async (id, req) => { | |
| // Get the frog instance | |
| const frog = await Frog.findById(id); | |
| if (!frog) throw new Error('Frog not found.'); | |
| // extract the file from the request object | |
| const file = await getFileFromRequest(req); | |
| // upload the file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { join, extname } = require('path'); | |
| const { readFileSync } = require('fs'); | |
| const AWS = require('aws-sdk'); | |
| const s3 = new AWS.S3({ /* CONFIG DATA */ }); | |
| /** | |
| * Helper method which takes the request object and returns a promise with the AWS S3 object details. | |
| */ | |
| const uploadFileToS3 = (file, options = {}) => { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const multiparty = require('multiparty'); | |
| /** | |
| * Helper method which takes the request object and returns a promise with a file. | |
| */ | |
| const getFileFromRequest = (req) => new Promise((resolve, reject) => { | |
| const form = new multiparty.Form(); | |
| form.parse(req, (err, fields, files) => { | |
| if (err) reject(err); | |
| const file = files['file'][0]; // get the file from the returned files object |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "myapp-spa", | |
| "version": "1.0.0", | |
| "scripts": { | |
| "start": "serve --single --cache=60000" | |
| }, | |
| "dependencies": { | |
| "serve": "latest" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
| <title>404 Not Found | My App</title> | |
| </head> | |
| <body> | |
| <script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const queryString = require('query-string'); | |
| ... | |
| const params = queryString.parse(document.location.search); | |
| const redirect = params.redirect; // this would be "abcdefg" if the query was "?redirect=abcdefg" | |
| if (document.location.pathname === '/' && redirect) { | |
| document.location.assign(`${document.location.origin}/${redirect}`); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { google } from 'googleapis'; | |
| const googleConfig = { | |
| clientId: '<GOOGLE_CLIENT_ID>', // e.g. asdfghjkljhgfdsghjk.apps.googleusercontent.com | |
| clientSecret: '<GOOGLE_CLIENT_SECRET>', // e.g. _ASDFA%DFASDFASDFASD#FAD- | |
| redirect: 'https://your-website.com/google-auth' // this must match your google api settings | |
| }; | |
| /** | |
| * Create the google auth object which gives us access to talk to google's apis. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * This scope tells google what information we want to request. | |
| */ | |
| const defaultScope = [ | |
| 'https://www.googleapis.com/auth/plus.me', | |
| 'https://www.googleapis.com/auth/userinfo.email', | |
| ]; | |
| /** | |
| * Get a url which will open the google sign-in page and request access to the scope provided (such as calendar events). |
OlderNewer