Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Antonio Paya antonioalfa22

🏠
Working from home
View GitHub Profile
@antonioalfa22
antonioalfa22 / docker
Created Sep 25, 2020
go-rest-template Dockerfile
View docker
FROM golang:1.12-alpine
RUN apk add --no-cache git gcc g++
# Set the Current Working Directory inside the container
WORKDIR /app
# We want to populate the module cache based on the go.{mod,sum} files.
COPY go.mod .
COPY go.sum .
View gist:24ecd3e3c72642d09f9cdc8e200b80b2
get-docs:
go get -u github.com/swaggo/swag/cmd/swag
docs: get-docs
swag init --dir cmd/api --parseDependency --output docs
build:
go build -o bin/restapi cmd/api/main.go
run:
@antonioalfa22
antonioalfa22 / express-session.js
Created Mar 31, 2020
Express Session Example
View express-session.js
var session = require('express-session');
app.set('trust proxy', 1) // trust first proxy
app.use(
session({
secret : << Your secret >>,
name : 'IdSessionPaya',
})
);
View express-rate-limit.js
import * as rateLimit from "express-rate-limit";
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 20 // 20 requests
});
this.app.use('/api/login', limiter);
View helmet.js
const express = require('express')
const helmet = require('helmet')
const app = express()
app.use(helmet())
@antonioalfa22
antonioalfa22 / https.js
Created Mar 31, 2020
HTTPS with ExpressJS
View https.js
import * as https from "https";
import * as fs from "fs";
import * as path from "path";
const HTTPS_PORT = Number.parseInt(process.env.HTTPS_PORT) || 443;
const options = {
key: fs.readFileSync(path.resolve(__dirname, "../certs/certificado.key")),
cert: fs.readFileSync(path.resolve(__dirname, "../certs/certificado.cert"))
};
View npm-commands.sh
# List installed packages to ensure that we use only the necessary ones (add -g for global packages):
npm list [-g] --depth 0
# Uninstall package (add -g for global packages)
npm uninstall [-g] <package-name>
# Delete packages (add -g for global packages)
npm rm --save [-g] <package-name>
# Compare versions of current packages with the most recent versions (add -g for global packages)
View redFabric.js
'use strict';
var fabricClient = require('./config/FabricClient');
class RedFabric {
constructor(userName) {
this.currentUser;
this.issuer;
this.userName = userName;
this.connection = fabricClient;
View routes.js
module.exports = function (app, redFabric) {
/**
* GET all laptops
*/
app.get("/api/laptops", function (req, res) {
redFabric.init().then(function() {
return redFabric.queryAllLaptops()
}).then(function (data) {
res.status(200).json(data)
View sever.js
'use strict';
/**
* _ _ ______ _______ _ _ _______ ____ _____ _____ _
* | | | | ____| |__ __| | | |__ __/ __ \| __ \|_ _| /\ | |
* | |__| | |__ | | | | | | | | | | | | |__) | | | / \ | |
* | __ | __| | | | | | | | | | | | | _ / | | / /\ \ | |
* | | | | | | | | |__| | | | | |__| | | \ \ _| |_ / ____ \| |____
* |_| |_|_| |_| \____/ |_| \____/|_| \_\_____/_/ \_\______|
*
* ===========================================================================