2021-07-20 09:29:42 +08:00
|
|
|
const {resolve} = require('path');
|
|
|
|
const express = require('express');
|
|
|
|
const Router = express.Router;
|
|
|
|
|
|
|
|
const host = 'localhost';
|
|
|
|
const port = 8000;
|
|
|
|
const app = express();
|
|
|
|
const webServer = Router();
|
2022-08-08 06:05:39 +08:00
|
|
|
const wwwDir = resolve(__dirname, './www');
|
2021-07-20 09:29:42 +08:00
|
|
|
const devDir = resolve(__dirname, './www-dev');
|
2022-08-08 06:05:39 +08:00
|
|
|
const webIndex = resolve(wwwDir, './index.html');
|
2021-07-20 09:29:42 +08:00
|
|
|
|
|
|
|
webServer.get('/', (_, res) => res.sendFile(webIndex));
|
|
|
|
|
2022-08-08 06:05:39 +08:00
|
|
|
webServer.use('/auth', express.static(resolve(wwwDir, './auth')));
|
2022-08-19 00:56:57 +08:00
|
|
|
webServer.use('/lib', express.static(resolve(wwwDir, './lib')));
|
2022-08-08 06:05:39 +08:00
|
|
|
|
2022-11-13 09:48:34 +08:00
|
|
|
webServer.get('/bundle.css', async (_, res) => res.sendFile(resolve(devDir, `./bundle.css`)));
|
|
|
|
webServer.get('/bundle.js', async (_, res) => res.sendFile(resolve(devDir, `./bundle.js`)));
|
2021-07-20 09:29:42 +08:00
|
|
|
|
|
|
|
app.use('/', webServer);
|
|
|
|
app.get('*', (_, res) => res.redirect('/'));
|
|
|
|
|
|
|
|
app.listen(port, host, () => {
|
|
|
|
const timestamp = new Date().toISOString().slice(0, 19).replace('T', ' ');
|
|
|
|
console.info(`Serving from: http://${host}:${port}`);
|
|
|
|
console.info(`Server started at: ${timestamp}`);
|
|
|
|
});
|