Skip to content

Commit a227f38

Browse files
feat(Dev): open server in local dev environment
1 parent e43718a commit a227f38

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
"lint": "npx eslint . -c ./.github/linters/.eslintrc.yml",
3333
"package": "npx ncc build src/index.ts -o dist --source-map --license licenses.txt",
3434
"package:watch": "npm run package -- --watch",
35-
"package:watch:local": "npx ncc build src/index.ts -o .local/dist --source-map --license licenses.txt",
36-
"dev": "npm run package:watch:local && OPENAPI_DIFF_NODE_ENV=local node ./.local/dist/index.js",
35+
"package:local": "npx ncc build src/index.ts -o .local/dist --source-map --license licenses.txt",
36+
"package:watch:local": "npm run package:local -- --watch",
37+
"dev": "npm run package:watch:local && npm run dev:nodemon",
38+
"dev:nodemon": "OPENAPI_DIFF_NODE_ENV=local nodemon ./.local/dist/index.js --watch ./.local/dist/index.js",
3739
"test": "npx jest",
3840
"all": "npm run format:write && npm run lint && npm run test && npm run coverage && npm run package"
3941
},

src/main.ts

+21
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { stdout } from 'process'
44
import { getFileFromBranch } from './utils/get-file-from-branch'
55
import { diffOpenapiObject } from './utils/diff-openapi-object'
66
import fs from 'fs'
7+
import * as http from 'http'
78
/**
89
* The main function for the action.
910
* @returns {Promise<void>} Resolves when the action is complete.
@@ -79,6 +80,26 @@ export async function run(): Promise<void> {
7980
if (!isLocal) {
8081
core.setOutput('result', result)
8182
}
83+
84+
if (isLocal) {
85+
// Define the port number
86+
const PORT = 5050
87+
88+
// Create a server
89+
const server: http.Server = http.createServer((req, res) => {
90+
// Set the response header
91+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' })
92+
93+
// send reponse with result
94+
res.end(result) //sds
95+
res.end('dd')
96+
})
97+
98+
// Start the server
99+
server.listen(PORT, () => {
100+
console.log(`Server is running on port ${PORT}`)
101+
})
102+
}
82103
} catch (error) {
83104
// Fail the workflow run if an error occurs
84105
if (error instanceof Error) core.setFailed(error.message)

0 commit comments

Comments
 (0)