Selaa lähdekoodia

添加 http 服务。

oldj 8 vuotta sitten
vanhempi
sitoutus
dbab4f193c
4 muutettua tiedostoa jossa 37 lisäystä ja 1 poistoa
  1. 10 0
      app/configs.js
  2. 2 1
      app/package.json
  3. 1 0
      app/server/Server.js
  4. 24 0
      app/server/http/app.js

+ 10 - 0
app/configs.js

@@ -0,0 +1,10 @@
+/**
+ * @author oldj
+ * @blog https://oldj.net
+ */
+
+'use strict'
+
+module.exports = {
+  PORT: 50761
+}

+ 2 - 1
app/package.json

@@ -9,7 +9,8 @@
   "author": "oldj",
   "license": "MIT",
   "dependencies": {
+    "express": "^4.15.2",
     "js-beautify": "^1.6.12",
     "md5-file": "^3.1.1"
   }
-}
+}

+ 1 - 0
app/server/Server.js

@@ -8,6 +8,7 @@
 const EventEmitter = require('events')
 const {ipcMain} = require('electron')
 const actions = require('./actions/index')
+const app = require('./http/app')
 
 let renderer
 let svr = new EventEmitter()

+ 24 - 0
app/server/http/app.js

@@ -0,0 +1,24 @@
+/**
+ * @author oldj
+ * @blog https://oldj.net
+ */
+
+'use strict'
+
+const {PORT} = require('../../configs')
+const express = require('express')
+const app = express()
+
+app.get('/', function (req, res) {
+  res.send('Hello SwitchHost!')
+})
+
+app.get('/remote-test', function (req, res) {
+  res.send(`# remote-test\n# ${(new Date()).toString()}`)
+})
+
+app.listen(PORT, function () {
+  console.log(`SwitchHosts! HTTP server listening on port ${PORT}!`)
+})
+
+module.exports = app