Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
game-cli
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
game-cli
Commits
c5782ca4
Commit
c5782ca4
authored
Oct 24, 2018
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mock/serve 支持ssl
parent
436dab90
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
126 additions
and
22 deletions
+126
-22
.gitignore
.gitignore
+4
-0
cli.js
bin/cli.js
+1
-1
game-cli-mock.js
bin/game-cli-mock.js
+8
-3
game-cli-serve.js
bin/game-cli-serve.js
+8
-3
index.js
bin/http-server/index.js
+28
-9
index.js
bin/json-server/index.js
+20
-6
localhost.conf
ssl/localhost.conf
+52
-0
localhost.sh
ssl/localhost.sh
+5
-0
No files found.
.gitignore
View file @
c5782ca4
...
...
@@ -74,3 +74,7 @@ typings/
# Serverless directories
.serverless
/ssl/*.crt
/ssl/*.pem
/ssl/*.key
/ssl/*.cer
bin/cli.js
View file @
c5782ca4
...
...
@@ -3,7 +3,7 @@
const
program
=
require
(
'commander'
);
program
.
version
(
'0.0.
1
'
)
.
version
(
'0.0.
2
'
)
.
description
(
'game command line interface'
)
.
command
(
'init [name]'
,
'Initialize a project with template'
).
alias
(
'i'
)
.
command
(
'mock'
,
'Mock server'
).
alias
(
'm'
)
...
...
bin/game-cli-mock.js
View file @
c5782ca4
...
...
@@ -6,6 +6,8 @@ program
.
option
(
'-h, --host [string]'
,
'server host'
,
'localhost'
)
.
option
(
'-p, --port [number]'
,
'server port'
,
3000
)
.
option
(
'-f, --folder [string]'
,
'folder of json files'
,
'./'
)
.
option
(
'-k, --key-file [string]'
,
'ssl key file'
)
.
option
(
'-c, --cert-file [string]'
,
'ssl cert file'
)
.
parse
(
process
.
argv
);
async
function
execute
()
{
...
...
@@ -15,10 +17,13 @@ async function execute() {
host
:
program
.
host
,
port
:
program
.
port
,
folder
:
program
.
folder
,
keyFile
:
program
.
keyFile
,
certFile
:
program
.
certFile
,
}).
then
(
({
host
,
port
,
jsonPath
})
=>
{
console
.
log
(
`Json server start at http://
${
host
}
:
${
port
}
`
);
console
.
log
(
'Json path: '
,
jsonPath
);
({
host
,
port
,
jsonPath
,
isSSL
})
=>
{
const
schema
=
isSSL
?
'https'
:
'http'
;
console
.
log
(
`
${
schema
}
server start at
${
schema
}
://
${
host
}
:
${
port
}
`
);
console
.
log
(
`
${
schema
}
path:
${
jsonPath
}
`
);
},
(
e
)
=>
{
console
.
log
(
e
);
...
...
bin/game-cli-serve.js
View file @
c5782ca4
...
...
@@ -6,6 +6,8 @@ program
.
option
(
'-h, --host [string]'
,
'server host'
,
'localhost'
)
.
option
(
'-p, --port [number]'
,
'server port'
,
3001
)
.
option
(
'-f, --folder [string]'
,
'folder of static files'
,
'./'
)
.
option
(
'-k, --key-file [string]'
,
'ssl key file'
)
.
option
(
'-c, --cert-file [string]'
,
'ssl cert file'
)
.
parse
(
process
.
argv
);
async
function
execute
()
{
...
...
@@ -15,10 +17,13 @@ async function execute() {
host
:
program
.
host
,
port
:
program
.
port
,
folder
:
program
.
folder
,
keyFile
:
program
.
keyFile
,
certFile
:
program
.
certFile
,
}).
then
(
({
host
,
port
,
publicPath
})
=>
{
console
.
log
(
`Http server start at http://
${
host
}
:
${
port
}
`
);
console
.
log
(
'Http path: '
,
publicPath
);
({
host
,
port
,
publicPath
,
isSSL
})
=>
{
const
schema
=
isSSL
?
'https'
:
'http'
;
console
.
log
(
`
${
schema
}
server start at
${
schema
}
://
${
host
}
:
${
port
}
`
);
console
.
log
(
`
${
schema
}
path:
${
publicPath
}
`
);
},
(
e
)
=>
{
console
.
log
(
e
);
...
...
bin/http-server/index.js
View file @
c5782ca4
...
...
@@ -3,22 +3,41 @@
*
* http serve
*/
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs'
);
const
h
andler
=
require
(
'serve-handler'
);
const
serveH
andler
=
require
(
'serve-handler'
);
const
http
=
require
(
'http'
);
const
https
=
require
(
'https'
);
let
publicPath
;
function
handler
(
request
,
response
){
return
serveHandler
(
request
,
response
,
{
public
:
publicPath
,
});
}
exports
.
start
=
function
(
options
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
{
port
,
host
,
folder
}
=
options
;
const
{
port
,
host
,
folder
,
keyFile
,
certFile
}
=
options
;
const
publicPath
=
path
.
resolve
(
folder
);
publicPath
=
path
.
resolve
(
folder
);
if
(
fs
.
existsSync
(
publicPath
))
{
const
server
=
http
.
createServer
((
request
,
response
)
=>
{
return
handler
(
request
,
response
,
{
public
:
publicPath
,
});
});
let
sslOpts
;
if
(
keyFile
&&
certFile
){
const
keyContent
=
fs
.
readFileSync
(
keyFile
,
'utf8'
),
certContent
=
fs
.
readFileSync
(
certFile
,
'utf8'
);
if
(
keyContent
&&
certContent
){
sslOpts
=
{
key
:
keyContent
,
cert
:
certContent
};
}
}
const
server
=
sslOpts
?
https
.
createServer
(
sslOpts
,
handler
)
:
http
.
createServer
(
handler
);
server
.
on
(
'error'
,
(
err
)
=>
{
reject
(
err
.
message
);
...
...
@@ -26,7 +45,7 @@ exports.start = function (options) {
server
.
listen
(
port
,
host
,
function
()
{
resolve
({
host
,
port
,
publicPath
,
host
,
port
,
publicPath
,
isSSL
:
!!
sslOpts
});
});
}
else
{
...
...
bin/json-server/index.js
View file @
c5782ca4
...
...
@@ -6,10 +6,12 @@
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs'
);
const
http
=
require
(
'http'
);
const
https
=
require
(
'https'
);
let
jsonPath
;
function
onRequest
(
request
,
response
)
{
function
handler
(
request
,
response
)
{
const
{
url
}
=
request
;
if
(
url
===
'/favicon.ico'
)
{
...
...
@@ -54,21 +56,33 @@ function onRequest(request, response) {
response
.
end
();
}
const
http
=
require
(
'http'
);
const
server
=
http
.
createServer
(
onRequest
);
exports
.
start
=
function
(
options
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
{
port
=
3000
,
host
=
'localhost'
,
folder
=
'./mock'
}
=
options
;
const
{
port
,
host
,
folder
,
keyFile
,
certFile
}
=
options
;
jsonPath
=
path
.
resolve
(
folder
);
if
(
fs
.
existsSync
(
jsonPath
))
{
let
sslOpts
;
if
(
keyFile
&&
certFile
){
const
keyContent
=
fs
.
readFileSync
(
keyFile
,
'utf8'
),
certContent
=
fs
.
readFileSync
(
certFile
,
'utf8'
);
if
(
keyContent
&&
certContent
){
sslOpts
=
{
key
:
keyContent
,
cert
:
certContent
};
}
}
const
server
=
sslOpts
?
https
.
createServer
(
sslOpts
,
handler
)
:
http
.
createServer
(
handler
);
server
.
on
(
'error'
,
(
err
)
=>
{
reject
(
err
.
message
);
});
server
.
listen
(
port
,
host
,
function
()
{
resolve
({
host
,
port
,
jsonPath
,
host
,
port
,
jsonPath
,
isSSL
:
!!
sslOpts
});
});
}
else
{
...
...
ssl/localhost.conf
0 → 100644
View file @
c5782ca4
[
req
]
default_bits
=
2048
default_keyfile
=
server
-
key
.
pem
distinguished_name
=
subject
req_extensions
=
req_ext
x509_extensions
=
x509_ext
string_mask
=
utf8only
[
subject
]
countryName
=
Country
Name
(
2
letter
code
)
countryName_default
=
US
stateOrProvinceName
=
State
or
Province
Name
(
full
name
)
stateOrProvinceName_default
=
NY
localityName
=
Locality
Name
(
eg
,
city
)
localityName_default
=
New
York
organizationName
=
Organization
Name
(
eg
,
company
)
organizationName_default
=
localhost
,
LLC
commonName
=
Common
Name
(
e
.
g
.
server
FQDN
or
YOUR
name
)
commonName_default
=
localhost
emailAddress
=
Email
Address
emailAddress_default
=
test
@
example
.
com
[
x509_ext
]
subjectKeyIdentifier
=
hash
authorityKeyIdentifier
=
keyid
,
issuer
basicConstraints
=
CA
:
FALSE
keyUsage
=
digitalSignature
,
keyEncipherment
subjectAltName
= @
alternate_names
nsComment
=
"OpenSSL Generated Certificate"
[
req_ext
]
subjectKeyIdentifier
=
hash
basicConstraints
=
CA
:
FALSE
keyUsage
=
digitalSignature
,
keyEncipherment
subjectAltName
= @
alternate_names
nsComment
=
"OpenSSL Generated Certificate"
[
alternate_names
]
DNS
.
1
=
localhost
IP
.
1
=
192
.
168
.
95
.
2
\ No newline at end of file
ssl/localhost.sh
0 → 100755
View file @
c5782ca4
#!/bin/bash
openssl req
-config
localhost.conf
-new
-sha256
-newkey
rsa:2048
-nodes
-keyout
localhost.key
-x509
-days
365
-out
localhost.crt
cat
localhost.crt localhost.key
>
localhost.pem
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment