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
// Create a .env file at your project root: | |
// add your variables: | |
VITE_API_KEY=your_api_key_here | |
// Accessing Environment Variables: | |
// In your Vite project, you can access the environment variable directly: | |
const apiKey = import.meta.env.VITE_API_KEY; |
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 express = require('express'); | |
const app = express(); | |
const session = require('express-session'); | |
// Assuming we have a function to get user data | |
const getUserById = require('./getUserById'); | |
app.use(session({ | |
secret: 'your-secret', | |
resave: false, |
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
<script> | |
import { onMount } from 'svelte'; | |
import axios from 'axios'; | |
let csrfToken = ''; | |
onMount(async () => { | |
try { | |
const response = await axios.get('/api/get-csrf-token'); | |
csrfToken = response.data.csrfToken; |
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
codeserver { | |
# ... other configuration ... | |
add_header Content-Security-Policy "script-src 'self' 'unsafe-inline' http://localhost:5173 https://static.cloudflareinsights.com https://www.clarity.ms https://accounts.google.com https://upload-widget.cloudinary.com https://maps.googleapis.com https://www.googletagmanager.com;" | |
# ... other configuration ... | |
} |
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
# CSP Header | |
header Content-Security-Policy "script-src 'self' 'unsafe-inline' http://localhost:5173 https://static.cloudflareinsights.com https://www.clarity.ms https://accounts.google.com https://upload-widget.cloudinary.com https://maps.googleapis.com https://www.googletagmanager.com;" |
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 React, { useState } from 'react'; | |
import DOMPurify from 'dompurify'; | |
const UserComments = () => { | |
const [comments, setComments] = useState([ | |
// Assume these comments are fetched from a server | |
{ id: 1, content: '<script>alert("XSS Attack!")</script>Great article!' }, | |
{ id: 2, content: 'Really enjoyed this post.' }, | |
// More comments... | |
]); |
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 React from "react"; | |
import Skeleton from "react-loading-skeleton"; | |
const imgUrl = | |
"https://cdn-images-1.medium.com/fit/c/50/50/1*Rhzd_aZYgwP2gocFecKi0Q.png"; | |
export default function BlogPost({ title, body, subTitle }) { | |
return ( | |
<div> | |
{body ? ( |
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 React, { useState, useEffect } from "react"; | |
import "./styles.css"; | |
import BlogPost from "./BlogPost"; | |
const blogPost = { | |
title: "Indrek Lasn Blog Post", | |
subTitle: "This is a subtitle for the skeleton loader", | |
body: | |
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." | |
}; |
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 React from "react"; | |
import Skeleton from "react-loading-skeleton"; | |
export default function BlogPost({ title, body, subTitle }) { | |
return ( | |
<div> | |
<h1>{title || <Skeleton />}</h1> | |
<h3>{subTitle || <Skeleton />}</h3> | |
<p>{body || <Skeleton count={6} />}</p> |
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 sharp = require("sharp"); | |
sharp("example-image.jpg") | |
.resize({ width: 500, height: 450 }) | |
.flip() | |
.toFormat("png") | |
.png({ quality: 100 }) | |
.toFile("flip-output.png"); |
NewerOlder