This file contains 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
/********** | |
server.ts | |
--------------- | |
Simple file written in ES6 to serve a ExpressJS/NextJS Server. | |
Uses SSL, Compression, redirection and service worker routing. See server config file at : | |
https://github.com/glemiere/nextjs-starter/tree/master/config | |
--------------- | |
Requires Let's Encrypt SSL Certificate : | |
https://letsencrypt.org/ | |
**********/ |
This file contains 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 = { | |
webpack: function (cfg) { | |
const originalEntry = cfg.entry | |
cfg.entry = async () => { | |
const entries = await originalEntry() | |
if ( | |
entries['main.js'] && | |
!entries['main.js'].includes('./client/polyfills.js') | |
) { |
This file contains 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
'use strict'; | |
const assert = require('assert'); | |
/** | |
* The redis client is https://github.com/luin/ioredis | |
*/ | |
/* | |
const redisClient = new Redis({ |
This file contains 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
// a few seconds ago | |
moment.fn.fromNowOrNow = function (a) { | |
if (Math.abs(moment().diff(this)) < 25000) { // 25 seconds before or after now | |
return 'just now'; | |
} | |
return this.fromNow(a); | |
} | |
// check expiry | |
const isExpired = moment().isAfter(activity.endDate); |
This file contains 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
// Find one and remove entity afterwards | |
Charity.findOne({ cuid: userCuid }); | |
.exec() | |
.then(entity => { | |
if (!entity) res.status(404).end(); | |
else { | |
entity.remove() | |
.then(() => res.status(204).end()); | |
} | |
}); |
This file contains 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
export const populateUserActions = (userCuid, period = { from: new Date(), to: null }) => { | |
const aggregation = [ | |
{ $match: { 'cuid': userCuid }}, | |
{ $lookup: CompanyLookup }, | |
{ $lookup: FundraisingLookup }, | |
{ $lookup: MissionLookup }, | |
{ $lookup: CreatedExperienceLookup }, | |
{ $lookup: SubscribedExperienceLookup }, | |
{ $project: { | |
...simpleUserProjection, |
This file contains 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
Show hidden characters
{ | |
"presets": [ | |
["@babel/preset-env", { | |
"modules": false, | |
"useBuiltIns": "entry", | |
"targets": { | |
"browsers": [ | |
"> 0.25%", | |
"not dead" | |
], |
This file contains 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
let characterResponse = await fetch('http://swapi.co/api/people/2/') | |
let characterResponseJson = await characterResponse.json() | |
let films = await Promise.all( | |
characterResponseJson.films.map(async filmUrl => { | |
let filmResponse = await fetch(filmUrl) | |
return filmResponse.json() | |
}) | |
) | |
console.log(films) |
This file contains 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 optional code is used to register a service worker. | |
// register() is not called by default. | |
// This lets the app load faster on subsequent visits in production, and gives | |
// it offline capabilities. However, it also means that developers (and users) | |
// will only see deployed updates on subsequent visits to a page, after all the | |
// existing tabs open on the page have been closed, since previously cached | |
// resources are updated in the background. | |
// To learn more about the benefits of this model and instructions on how to |
This file contains 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
"husky": { | |
"hooks": { | |
"pre-commit": "lint-staged" | |
} | |
}, | |
"lint-staged": { | |
"*.{js,jsx}": "eslint --cache --fix" | |
}, | |
/** |