2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-05-17 17:09:37 +03:00
Files
vue-meta/examples/server.js
T
2019-03-12 12:13:40 +01:00

36 lines
926 B
JavaScript

import fs from 'fs'
import path from 'path'
import consola from 'consola'
import express from 'express'
import rewrite from 'express-urlrewrite'
import webpack from 'webpack'
import webpackDevMiddleware from 'webpack-dev-middleware'
import WebpackConfig from './webpack.config.babel'
const app = express()
app.use(webpackDevMiddleware(webpack(WebpackConfig), {
publicPath: '/__build__/',
stats: {
colors: true,
chunks: false
}
}))
fs.readdirSync(__dirname)
.filter(file => file !== 'ssr')
.forEach((file) => {
if (fs.statSync(path.join(__dirname, file)).isDirectory()) {
app.use(rewrite('/' + file + '/*', '/' + file + '/index.html'))
}
})
app.use(express.static(__dirname))
const host = process.env.HOST || 'localhost'
const port = process.env.PORT || 3000
module.exports = app.listen(port, host, () => {
consola.info(`Server listening on http://${host}:${port}, Ctrl+C to stop`)
})