-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.js
29 lines (20 loc) · 951 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();
const path = require('path');
const DIR = 'dist';
const html = path.join(__dirname, DIR, 'index.html');
const handler = (req, res) => res.sendFile(html);
const routes = ['/', '/about/', '/posts', '/posts/*', '/tags', '/tag/*'];
routes.forEach(route => app.get(route, handler));
const css = path.join(__dirname, DIR, 'styles.css');
app.get('/styles.css', (req, res) => res.sendFile(css));
const js = path.join(__dirname, DIR, 'script.js');
app.get('/script.js', (req, res) => res.sendFile(js));
app.use(express.static(DIR));
// app.use('/', express.static(path.join(__dirname, DIR)));
const API = ['http://localhost:3000', 'https://pixelhandler.dev'][1];
app.use('/api', createProxyMiddleware({target: API, changeOrigin: true}));
app.listen(8081, function () {
console.log('Running at http://localhost:8081');
});