添加 server 启动
This commit is contained in:
36
mobile-web/server/server.prod.js
Normal file
36
mobile-web/server/server.prod.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const path = require('path');
|
||||
const express = require('express');
|
||||
|
||||
const { chalkSuccess } = require('./config/chalk.config');
|
||||
const proxyConfig = require('./config/proxy.prod.config');
|
||||
const proxyBuild = require('./utils/proxy.build');
|
||||
|
||||
// create app server
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
// host proxy
|
||||
app.use(proxyBuild(proxyConfig));
|
||||
|
||||
// use index.html
|
||||
app.use(express.static(path.join(__dirname, 'dist/css')));
|
||||
app.use(express.static(path.join(__dirname, 'dist/js')));
|
||||
app.use(express.static(path.join(__dirname, 'dist')));
|
||||
|
||||
app.use((req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
|
||||
});
|
||||
|
||||
app.listen(port, error => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
} else {
|
||||
console.info(
|
||||
chalkSuccess(
|
||||
'==> 🌎 Listening on port %s. ' + 'Open up http://localhost:%s/ in your browser.'
|
||||
),
|
||||
port,
|
||||
port
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user