Skip to content

Instantly share code, notes, and snippets.

View roelvan's full-sized avatar
🏠
Working from home

Roel Vaneyghen roelvan

🏠
Working from home
View GitHub Profile
{
"version": 2,
"name": "to-be-or-not-to-be",
"regions": ["bru1"],
"builds": [
{ "src": "/static/**", "use": "@now/static" },
{ "src": "next.config.js", "use": "@now/next" }
],
"routes": [
{ "src": "/prijzen", "dest": "/pricing" },
/* eslint-disable */
// Fix for: https://github.com/zeit/next.js/issues/5750#issuecomment-442313585
const { PHASE_PRODUCTION_SERVER } =
process.env.NODE_ENV === 'development'
? {}
: require('next-server/constants');
const config = {
const withSass = require('@zeit/next-sass');
const config = {
publicRuntimeConfig: {
apiUrl: process.env.API_URL,
mediaUrl: process.env.MEDIA_URL
}
};
module.exports = withSass(config);
@roelvan
roelvan / dev-server.js
Created November 26, 2018 11:48
NOW v2 Local DEV env Node.js
require('dotenv').config();
const http = require('http');
const url = require('url');
// import NOW SETTINGS
const now = require('./now.json');
const PORT = process.env.PORT || 3030;
const routes = now.routes.reduce((map, route) => {
@roelvan
roelvan / logger.js
Created April 2, 2018 03:20
Logger hook
// A hook that logs service method before, after and error
// See https://github.com/winstonjs/winston for documentation
// about the logger.
const logger = require('winston');
const timber = require('timber');
const transport = new timber.transports.HTTPS(process.env.TIMBER_KEY);
timber.install(transport);
// To see more detailed messages, uncomment the following line
@roelvan
roelvan / resolvers.js
Created January 29, 2018 02:07
Fastjoin + batchloader to do a count
// const { makeCallingParams } = require('feathers-hooks-common');
const BatchLoader = require('@feathers-plus/batch-loader');
const { getUniqueKeys, getResultsByKey } = BatchLoader;
const QUERY = `
SELECT count("productId"), "productId"
FROM "inventoryItems"
WHERE "productId" = ANY (:productIds)
GROUP BY "productId"
`;
@roelvan
roelvan / slugify.hook.js
Last active January 27, 2018 04:56
Slugify a field based on another one - Feathers
// Can be run as a before and after hook
const { alterItems } = require('feathers-hooks-common');
const slug = require('slug');
module.exports = function (fromField, toField = 'slug') { // eslint-disable-line no-unused-vars
return alterItems(item => {
if (!item[fromField])
throw new Error(`No such field [${fromField}]`);
item[toField] = slug(item[fromField]);
});
@roelvan
roelvan / buyButtonSettings.js
Last active December 27, 2017 06:03
Beresterk
{
product: {
iframe: true,
buttonDestination: 'cart',
isButton: false,
layout: 'vertical',
manifest: ['product', 'option'],
width: '280px',
order: [
'img',
// Initialize our service with any options it requires
app.use('/tickets', createService(options), (req, res) => {
const doc = res.data;
doc.pipe(res);
return res.format({ 'application/pdf': () => doc.end() });
});
@roelvan
roelvan / tickets.class.js
Last active November 28, 2017 07:23
Generate PDF's and Barcodes with Feathers.js
const errors = require('feathers-errors');
const PDFDocument = require('pdfkit');
const bwipjs = require('bwip-js');
/* eslint-disable no-unused-vars */
class Service {
constructor (options) {
this.options = options || {};
}