Skip to content

Instantly share code, notes, and snippets.

// 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;
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,
<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;
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 ...
}
# 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;"
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...
]);
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 ? (
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."
};
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>
const sharp = require("sharp");
sharp("example-image.jpg")
.resize({ width: 500, height: 450 })
.flip()
.toFormat("png")
.png({ quality: 100 })
.toFile("flip-output.png");