-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (32 loc) · 947 Bytes
/
server.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
30
31
32
33
34
35
36
37
38
39
const path = require('path');
const express = require('express');
const Bundler = require('parcel-bundler');
function main() {
const parcel_option = {
entryFiles: [ './app/index.html' ],
publicUrl: '/api/',
};
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
const bundler = new Bundler(parcel_option.entryFiles, parcel_option);
const app = express();
app.use(function(req, res, next) {
if (req.originalUrl.startsWith('/api/')) {
next();
} else {
res.status(200).send(
'You are not requesting to target /api/.<br>' +
'Current path: ' + req.originalUrl);
}
});
const parcel_middleware = bundler.middleware();
app.use('/api', function(req, res, next) {
req.url = req.originalUrl;
parcel_middleware(req, res, next);
});
app.listen(3000, function() {
console.log('Server listening on port 3000.');
});
}
if (require.main === module) {
main();
}