bigly-chat/index.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-09-07 18:12:58 -04:00
import express from 'express';
import multer from 'multer';
import iterate from './routes.js';
import cookieParser from 'cookie-parser';
2024-09-18 18:47:09 -04:00
import ejs from "ejs";
2024-09-07 18:12:58 -04:00
const port = process.env.PORT || 3000;
const app = express();
const upload = multer({ dest: 'uploads/' });
app.use(cookieParser());
app.use('/static', express.static('static'));
2024-09-19 05:44:24 -04:00
app.use('/videos', express.static('videos'));
2024-09-27 03:59:23 -04:00
app.use('/pfp', express.static('pfp'));
2024-09-18 18:47:09 -04:00
app.engine('.ejs', ejs.__express);
app.set('views', './views');
app.set('view engine', 'ejs');
2024-09-07 18:12:58 -04:00
app.get('/', (req, res) => {
res.status(301).redirect('/client/main');
})
app.get('/client/:route', async (req, res) => {
2024-09-19 05:04:03 -04:00
await iterate(req, res, 'client');
2024-09-07 18:12:58 -04:00
})
app.get('/api/get/:route', async (req, res) => {
res.send(await iterate(req, res, 'get'));
})
app.post('/api/form/:route', upload.none(), async (req, res) => {
res.send(await iterate(req, res, 'form'));
})
2024-09-19 05:44:24 -04:00
app.post('/api/upload/:route', upload.single('file'), async (req, res) => {
res.send(await iterate(req, res, 'form'));
})
2024-10-19 21:28:52 -04:00
app.get('/pfp/*', (req,res) => {
res.redirect(301,'/static/img/logo.svg')
})
2024-10-24 22:41:21 -04:00
app.get('*', (req,res) => {
res.redirect(301,'/client/404');
})
2024-09-07 18:12:58 -04:00
app.listen(port, () => {
console.log(`App listening on port ${port}`)
})