- Create a
/netlify
folder and inside create/functions
folder, and inside create a.js
file for your function - OPTIONAL: require MongoClient if you are using MongoDB
- Create an async function named
handler
- OPTIONAL: Connect to the database, get your data, then close DB connection
- Return an object with
statusCode
,headers
(optional), andbody
properties
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
<!-- Simpler version on my portfolio site: | |
https://jameskernicky.netlify.app/ | |
https://github.com/Kernix13/personal-portfolio | |
--> | |
<button id="back-to-top-btn"><i class="fa-solid fa-angle-up"></i></button> | |
<!-- Bootstrap icon instead of font awesome --> | |
<svg | |
xmlns="http://www.w3.org/2000/svg" |
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
if (process.env.NODE_ENV !== 'production') { | |
require('dotenv').config(); | |
} | |
const express = require('express'); | |
const path = require('path'); | |
const mongoose = require('mongoose'); | |
const ejsMate = require('ejs-mate'); | |
const methodOverride = require('method-override'); |
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
// npm i express mongoose | |
// create a /models folder, inside create retreat.js, | |
// model name = 'Retreat', the schema = RetreatSchema | |
const mongoose = require('mongoose'); | |
const { Schema } = mongoose; | |
const RetreatSchema = new mongoose.Schema({ | |
title: String, | |
image: String, | |
price: Number, |
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
// add to app.js | |
const path = require('path'); | |
/* Set EJS as the view engine */ | |
app.set('view engine', 'ejs'); | |
app.set('views', path.join(__dirname, 'views')); | |
// change res.send to res.render | |
app.get('/', (req, res) => { | |
res.render('home'); |
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
// npm i express mongoose ejs | |
// in app.js | |
const express = require('express'); | |
const app = express(); | |
app.get('/', (req, res) => { | |
res.send('Home Route'); | |
}); | |
app.listen(3000, () => { |
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
// npm install cookie | |
const cookie = require('cookie'); | |
const handler = async (event) => { | |
const body = JSON.parse(event.body); | |
// pick a generic username and password for now | |
if (body.username == "some_name" && body.password == "some_password") { |
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
// Setting cookie for logged in admin | |
// run npm install cookie then: | |
// petadoption is the name of the cookie for this example | |
const cookie = require('cookie'); | |
function isAdmin(event) { | |
const incomingCookie = cookie.parse(event.headers.cookie || ''); | |
if (incomingCookie?.petadoption == 'apsodifugyhtjrkelwqzmxncbv0918273645') { | |
return true; |
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
/* | |
DELETE THIS COMMENT BLOCK | |
1. replace 'yourtheme' in yourtheme_google_print_scripts with your theme name | |
- it occurs twice in the code below | |
2. replace the URL below that ends with 'ABC123' with your URL | |
3. replace 'ABC123' argument below in the 'gtag' function | |
4. Paste all of the code to the bottom of your functions.php file in the child theme or custom theme | |
*/ | |
function yourtheme_google_print_scripts() { ?> | |
<!-- Global site tag (gtag.js) - Google Analytics --> |
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
<!-- Add before endwhile in single.php or as a plugin --> | |
<aside class="bgcolor4"> | |
<div class="container"> | |
<h3 class="custom-title"><?php esc_html_e('Similar articles you may like... ', 'tower') ?></h3> | |
<div class="row"> | |
<?php | |
$cats = wp_get_post_categories( get_the_ID(), ['fields'=>'ids',]); | |
$relatedPosts = get_posts( |
NewerOlder