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
// 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 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 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 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 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 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 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"; | |
const Planets = () => { | |
const [hasError, setErrors] = useState(false); | |
const [planets, setPlanets] = useState({}); | |
async function fetchData() { | |
const res = await fetch("https://swapi.co/api/planets/4/"); | |
res | |
.json() |
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
import React, { useState, useEffect } from "react"; | |
const Planets = () => { | |
const [hasError, setErrors] = useState(false); | |
const [planets, setPlanets] = useState({}); | |
useEffect(() => { | |
async function fetchData() { | |
const res = await fetch("https://swapi.co/api/planets/4/"); | |
res |
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
import React, { useEffect, useState, Fragment } from "react"; | |
import Tabletop from "tabletop"; | |
import "./styles.css"; | |
export default function App() { | |
const [data, setData] = useState([]); | |
useEffect(() => { | |
Tabletop.init({ | |
key: "1TK1Qj6kfA90KbmFAdnIOtKUttpJUhZoZuOPy925c6nQ", |
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
orbs: | |
react: thefrontside/react@0.2.0 | |
version: 2.1 | |
workflows: | |
push: | |
jobs: | |
- react/install | |
- react/eslint: | |
requires: | |
- react/install |
NewerOlder