fix: compiling

- only node service is module
- import module with async
- serve react app from node process
This commit is contained in:
cv
2021-05-30 12:22:59 +02:00
parent 74c5b44488
commit 95e87d6ab8
4 changed files with 104 additions and 36 deletions
+14 -3
View File
@@ -3,7 +3,12 @@ import { config } from './config/config.js';
// init database
import { Low, JSONFile } from 'lowdb';
import { join } from 'path';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const file = join('data/', config.database.filename);
const adapter = new JSONFile(file);
@@ -60,9 +65,11 @@ app.use('/events', eventsRouter);
app.use('/event', eventRouter);
app.use('/ontime', ontimeRouter);
// implement general router
app.get('/', (req, res) => {
res.send('ontime API');
// serve react
app.use(express.static(path.join(__dirname, '../../client/build')));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, '../../client', 'build', 'index.html'));
});
// Implement route for errors
@@ -87,3 +94,7 @@ server.listen(port, () =>
import { initiateOSC } from './controllers/OscController.js';
initiateOSC(config.osc);
export function init() {
console.log('init');
}