-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #849 from hackclub/vercel-fix
Vercel fix
- Loading branch information
Showing
6 changed files
with
148 additions
and
145 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import express from 'express'; | ||
|
||
import signUpEmail from "../backend/api/signUpEmail.js"; | ||
import checkSignIn from "../backend/api/checkSignIn.js"; | ||
import saveFile from "../backend/api/saveFile.js"; | ||
import getUser from "../backend/api/getUser.js"; | ||
import submitCode from "../backend/api/submitCode.js"; | ||
import getFiles from "../backend/api/getFiles.js"; | ||
import createShareLink from "../backend/api/createShareLink.js"; | ||
import logout from "../backend/api/logout.js"; | ||
import deleteFile from "../backend/api/deleteFile.js"; | ||
|
||
import { supabase } from "../backend/api/supabase.js"; | ||
|
||
const app = express(); | ||
|
||
app.use(express.json()); | ||
|
||
app.post('/signUpEmail', signUpEmail); | ||
app.post('/check-signed-in', checkSignIn); | ||
app.post('/get-files', getFiles); | ||
app.post('/save-file', saveFile); | ||
app.post('/delete-file', deleteFile); | ||
app.post('/logout', logout); | ||
app.post('/get-user', getUser); | ||
app.post('/submit-code', submitCode); | ||
app.post('/create-share-link', createShareLink); | ||
app.get('/read-share-link', async (req, res) => { | ||
const { id } = req.query; | ||
|
||
try { | ||
|
||
console.log("check in database"); | ||
// check if email is in database | ||
let { data: file, error: fileError } = await supabase | ||
.from('share_link') | ||
.select('*') | ||
.eq('id', id) | ||
.single(); | ||
|
||
if (fileError && fileError.message !== 'No rows found') { | ||
res.send("no share link here"); | ||
return; | ||
} | ||
|
||
res.send(file.content); | ||
} catch (error) { | ||
res.status(500).send({ error: error.message }); | ||
} | ||
}); | ||
app.get('/assembly', (req, res) => { | ||
res.redirect('https://github.com/hackclub/blot/blob/main/docs/assembly/ASSEMBLY.md'); | ||
}); | ||
app.get('/welcome-qr-code', (req, res) => { | ||
res.redirect('/assembly'); | ||
}); | ||
|
||
export default app; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import app from './api/index.js' | ||
import './build.js' | ||
|
||
import { fileURLToPath } from 'url'; | ||
import { dirname, join } from 'path'; | ||
|
||
import express from 'express'; | ||
import path from 'path'; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
app.use(express.static(join(__dirname, 'dist'))); | ||
|
||
app.use((req, res, next) => { | ||
let pathName = req.path; | ||
|
||
if (pathName === "/") pathName = "/index"; | ||
|
||
if (req.path.indexOf('.') === -1) { | ||
const file = path.join(__dirname, 'dist', `${pathName}.html`); | ||
res.sendFile(file, (err) => { | ||
if (err) next(); | ||
}); | ||
} else { | ||
next(); | ||
} | ||
}); | ||
|
||
app.use((req, res, next) => { | ||
const file = path.join(__dirname, 'dist', `404.html`); | ||
res.status(404).sendFile(file); | ||
}); | ||
|
||
const port = process.env.PORT || 3000; | ||
|
||
app.listen(port, () => { | ||
console.log(`Server running at http://localhost:${port}`); | ||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"version": 2, | ||
"cleanUrls": true, | ||
"rewrites": [{ "source": "/(.*)", "destination": "/api" }] | ||
} |