Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: 更改源文件夹后 express 错误
  • Loading branch information
gaoliang committed Jul 25, 2019
commit ab9c506e82c5419d077026654fd3022ad1abc56a
6 changes: 3 additions & 3 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@ function createWindow() {
menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)

const server = initServer()

const setting = {
mainWindow: win,
app,
baseDir: __dirname,
previewServer: null,
previewServer: server,
}

// Init app
const appInstance = new App(setting)
console.log('Main process runing...', appInstance.appDir) // DELETE ME
const server = initServer(`${appInstance.appDir}/output`)
appInstance.previewServer = server
}

// Quit when all windows are closed.
Expand Down
5 changes: 1 addition & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import express from 'express'
import http from 'http'
import { AddressInfo } from 'net'

export default function initServer(SitePath: string) {
export default function initServer() {
const server = express()
server.use(express.static(SitePath))
function listen(port: number) {
server.listen(port, 'localhost').on('error', (err: NodeJS.ErrnoException) => {
if (err) {
Expand Down
5 changes: 4 additions & 1 deletion src/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BrowserWindow, app } from 'electron'
import * as fse from 'fs-extra'
import * as path from 'path'
import Antd from 'ant-design-vue'
import express from 'express'
import EventClasses from './events/index'
import Posts from './posts'
import Tags from './tags'
Expand Down Expand Up @@ -118,7 +119,8 @@ export default class App {
setting,
commentSetting: commentSetting || this.db.commentSetting,
}


this.previewServer.use('/', express.static(`${this.appDir}/output`))
this.initEvents()
return {
...this.db,
Expand All @@ -142,6 +144,7 @@ export default class App {
await fse.writeFileSync(appConfigPath, jsonString)
const appConfig = await fse.readJsonSync(appConfigPath)
this.appDir = appConfig.sourceFolder
this.previewServer.use('/', express.static(`${this.appDir}/output`))

this.checkDir()

Expand Down