top 10 boilerplate ever
This commit is contained in:
commit
d0cc234857
17 changed files with 567 additions and 0 deletions
47
index.js
Normal file
47
index.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
import express from 'express';
|
||||
import multer from 'multer';
|
||||
import iterate from './routes.js';
|
||||
import cookieParser from 'cookie-parser';
|
||||
|
||||
const port = process.env.PORT || 3000;
|
||||
|
||||
const header = `<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<script src='/static/main.js'></script>
|
||||
<link rel='stylesheet' href='/static/main.css'>
|
||||
</head>
|
||||
<body>
|
||||
`
|
||||
|
||||
const footer = `
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
const app = express();
|
||||
const upload = multer({ dest: 'uploads/' });
|
||||
|
||||
app.use(cookieParser());
|
||||
app.use('/static', express.static('static'));
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.status(301).redirect('/client/main');
|
||||
})
|
||||
|
||||
app.get('/client/:route', async (req, res) => {
|
||||
let dat = await iterate(req, res, 'client');
|
||||
res.send(header + dat + footer);
|
||||
})
|
||||
|
||||
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.listen(port, () => {
|
||||
console.log(`App listening on port ${port}`)
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue