Skip to content

Commit def5f07

Browse files
authored
Merge pull request #379 from sasjs/js-services
chore: add instructions for bundling js services
2 parents 649cf0d + 426e81a commit def5f07

File tree

4 files changed

+61
-12
lines changed

4 files changed

+61
-12
lines changed

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Overview
2+
23
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4+
35
[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors-)
6+
47
<!-- ALL-CONTRIBUTORS-BADGE:END -->
58

69
This React seed app provides a wrapper for `@sasjs/adapter`, a lightning fast adapter for talking to SAS - on Viya, EBI, or SASjs Server.
710

8-
911
## Frontend Web
1012

1113
If you are running on SAS 9 you need to set `serverType` to SAS9 in `sasContext.tsx`.
@@ -18,14 +20,14 @@ If you are running locally you will also need to whitelist `localhost` on the se
1820

1921
## Backend Services
2022

21-
The best way to deploy SAS services is using the [SASjs CLI](https://cli.sasjs.io). Simply [install](https://cli.sasjs.io/installation/), update the `defaultTarget` attribute in the [sasjsconfig.json](https://github.com/sasjs/react-seed-app/blob/main/sasjs/sasjsconfig.json) file, and run the following commands:
23+
The best way to deploy SAS services is using the [SASjs CLI](https://cli.sasjs.io). Simply [install](https://cli.sasjs.io/installation/), update the `defaultTarget` attribute in the [sasjsconfig.json](https://github.com/sasjs/react-seed-app/blob/main/sasjs/sasjsconfig.json) file, and run the following commands:
2224

2325
```bash
24-
sasjs auth
26+
sasjs auth
2527
sasjs cbd
2628
```
2729

28-
This will first authenticate to your target (follow the prompts) and after that you can just run `sasjs cbd` to rebuild and deploy your services. If you set `streamweb:true` in the sasjsconfig.json it will also deploy your frontend as a streaming app (no need for a web server).
30+
This will first authenticate to your target (follow the prompts) and after that you can just run `sasjs cbd` to rebuild and deploy your services. If you set `streamweb:true` in the sasjsconfig.json it will also deploy your frontend as a streaming app (no need for a web server).
2931

3032
If you are just looking to build quickly and don't have time to install NPM then you can also create the web services on ANY version of SAS by running the code below.
3133

@@ -60,6 +62,15 @@ This app will work on all versions of SAS Viya, in SAS 9 EBI from 9.3 and above,
6062

6163
It will not work on SAS University edition.
6264

65+
## Backend Services in JavaScript
66+
67+
If you are writing services in JS and your service depends on any third party library/package then you need to bundle that service before deploying it to sasjs server otherwise the service wouldn't work. You can choose any bundler for this process. One possible option could be `webpack`. And if you choose webpack then you can use it like:<br/>
68+
`npx webpack --mode none --target node --entry <path-of-file-to-bundle/build> --output-path <path-of-output-folder> --output-filename <name-of-output-file>`
69+
<br/>
70+
71+
In our case we have a mock service at path `sasjs/mocks/appinit.js` and we want to build and make it ready for deployment. So, we have to run following in terminal:<br/>
72+
`npx webpack --mode none --target node --entry ./sasjs/mocks/appinit.js --output-path sasjsbuild/mocks --output-filename appinit.js`
73+
6374
### Code Style
6475

6576
This project uses Prettier to format code.

package-lock.json

Lines changed: 20 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@material-ui/lab": "^4.0.0-alpha.60",
2828
"@mui/icons-material": "^5.8.2",
2929
"@mui/material": "^5.2.6",
30-
"@sasjs/adapter": "3.10.14",
30+
"@sasjs/adapter": "3.10.16",
3131
"@sasjs/core": "4.34.2",
3232
"@sasjs/utils": "^2.47.0",
3333
"axios": "^0.27.2",
@@ -54,6 +54,7 @@
5454
"babel-loader": "^8.2.3",
5555
"copy-webpack-plugin": "^10.2.4",
5656
"css-loader": "^6.7.1",
57+
"date-and-time": "2.4.1",
5758
"dotenv": "^16.0.1",
5859
"file-loader": "^6.2.0",
5960
"html-webpack-plugin": "5.5.0",

sasjs/mocks/appinit.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const date = require('date-and-time')
2+
3+
const now = new Date()
4+
5+
_webout = {
6+
SYSDATE: date.format(now, 'DDMMMYY'),
7+
SYSTIME: date.format(now, 'HH:mm'),
8+
areas: [
9+
{ AREA: 'Adak' },
10+
{ AREA: 'Adel' },
11+
{ AREA: 'Afognak' },
12+
{ AREA: 'Ajo' },
13+
{ AREA: 'Albany' },
14+
{ AREA: 'Albuquerque' },
15+
{ AREA: 'Alturas' },
16+
{ AREA: 'Ashton' },
17+
{ AREA: 'Atka' },
18+
{ AREA: 'Atlanta' },
19+
{ AREA: 'Attu' },
20+
{ AREA: 'Aztec' }
21+
]
22+
}
23+
24+
_webout = JSON.stringify(_webout)

0 commit comments

Comments
 (0)