bigly-chat/index.js
2024-10-24 22:41:21 -04:00

50 lines
No EOL
1.2 KiB
JavaScript

import express from 'express';
import multer from 'multer';
import iterate from './routes.js';
import cookieParser from 'cookie-parser';
import ejs from "ejs";
const port = process.env.PORT || 3000;
const app = express();
const upload = multer({ dest: 'uploads/' });
app.use(cookieParser());
app.use('/static', express.static('static'));
app.use('/videos', express.static('videos'));
app.use('/pfp', express.static('pfp'));
app.engine('.ejs', ejs.__express);
app.set('views', './views');
app.set('view engine', 'ejs');
app.get('/', (req, res) => {
res.status(301).redirect('/client/main');
})
app.get('/client/:route', async (req, res) => {
await iterate(req, res, 'client');
})
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'));
})
app.post('/api/upload/:route', upload.single('file'), async (req, res) => {
res.send(await iterate(req, res, 'form'));
})
app.get('/pfp/*', (req,res) => {
res.redirect(301,'/static/img/logo.svg')
})
app.get('*', (req,res) => {
res.redirect(301,'/client/404');
})
app.listen(port, () => {
console.log(`App listening on port ${port}`)
})